feat: Stream download, extract and parse datasets

This commit is contained in:
Lucàs
2024-09-28 16:19:43 +02:00
parent 5a00871319
commit ffc1ad3e84
32 changed files with 501 additions and 791 deletions
+7
View File
@@ -0,0 +1,7 @@
import { Duplex } from "node:stream";
interface Archive {
extract(source: string): Duplex;
}
export default Archive;
+12
View File
@@ -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;
+7
View File
@@ -0,0 +1,7 @@
enum ArchiveType {
ZIP = ".zip",
GZIP = ".gzip",
GZ = ".gz",
}
export default ArchiveType;
+12
View File
@@ -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;
+15
View File
@@ -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;
+7
View File
@@ -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";