mirror of
https://github.com/kmitresse/Compo-Service-Log-Project.git
synced 2026-07-09 12:07:45 +00:00
feat: Stream download, extract and parse datasets
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
import { Duplex } from "node:stream";
|
||||
|
||||
interface Archive {
|
||||
extract(source: string): Duplex;
|
||||
}
|
||||
|
||||
export default Archive;
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Archive, ZipArchive, ArchiveType, GzipArchive } from "./";
|
||||
|
||||
class ArchiveFactory {
|
||||
static getArchive(archiveType: ArchiveType): Archive {
|
||||
if (archiveType === ArchiveType.ZIP) return ZipArchive.instance;
|
||||
if ([ArchiveType.GZIP, ArchiveType.GZ].includes(archiveType)) return GzipArchive.instance;
|
||||
|
||||
throw new Error("Unsupported archive type");
|
||||
}
|
||||
}
|
||||
|
||||
export default ArchiveFactory;
|
||||
@@ -0,0 +1,7 @@
|
||||
enum ArchiveType {
|
||||
ZIP = ".zip",
|
||||
GZIP = ".gzip",
|
||||
GZ = ".gz",
|
||||
}
|
||||
|
||||
export default ArchiveType;
|
||||
@@ -0,0 +1,12 @@
|
||||
import { createGunzip } from "node:zlib";
|
||||
import { Duplex } from "node:stream";
|
||||
import { Archive } from "./";
|
||||
|
||||
class GzipArchive implements Archive {
|
||||
public static instance: Archive = new GzipArchive();
|
||||
|
||||
public extract(source: string): Duplex {
|
||||
return createGunzip();
|
||||
}
|
||||
}
|
||||
export default GzipArchive;
|
||||
@@ -0,0 +1,15 @@
|
||||
import { Archive } from "./";
|
||||
import { Duplex } from "node:stream";
|
||||
import { ParseOne } from "unzipper";
|
||||
|
||||
class ZipArchive implements Archive {
|
||||
public static instance: Archive = new ZipArchive();
|
||||
|
||||
public extract(source: string): Duplex {
|
||||
return ParseOne(new RegExp(source), {
|
||||
forceStream: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default ZipArchive;
|
||||
@@ -0,0 +1,7 @@
|
||||
export { default as ArchiveType } from "./ArchiveType";
|
||||
|
||||
export { default as ArchiveFactory } from "./ArchiveFactory";
|
||||
export { default as Archive } from "./Archive";
|
||||
|
||||
export { default as ZipArchive } from "./ZipArchive";
|
||||
export { default as GzipArchive } from "./GzipArchive";
|
||||
Reference in New Issue
Block a user