Create CSV reader scaffolding

This commit is contained in:
2025-04-01 13:52:58 +02:00
parent 196437f91d
commit cb0a25bb22
3 changed files with 22 additions and 0 deletions

12
src/csv/decoder.ts Normal file
View File

@@ -0,0 +1,12 @@
import { decode } from "windows-1250";
import { Transform } from 'stream';
export default new Transform({
transform(chunk, encoding, callback) {
try {
callback(null, decode(chunk));
} catch(error: any) {
callback(error);
}
},
});

1
src/csv/index.ts Normal file
View File

@@ -0,0 +1 @@
export { default as openCsv } from "./pipeline";

9
src/csv/pipeline.ts Normal file
View File

@@ -0,0 +1,9 @@
import Papa from "papaparse";
import fs from "fs";
import decoder from "./decoder";
export default function(file: string, config?: Papa.ParseConfig) {
return fs.createReadStream(file)
.pipe(decoder)
.pipe(Papa.parse(Papa.NODE_STREAM_INPUT, config))
}