Create CSV reader scaffolding
This commit is contained in:
12
src/csv/decoder.ts
Normal file
12
src/csv/decoder.ts
Normal 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
1
src/csv/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { default as openCsv } from "./pipeline";
|
||||
9
src/csv/pipeline.ts
Normal file
9
src/csv/pipeline.ts
Normal 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))
|
||||
}
|
||||
Reference in New Issue
Block a user