Browse Source

Create generated file

node10
root 12 months ago
parent
commit
8718f552f1
  1. 7
      src/models/file.js

7
src/models/file.js

@ -123,7 +123,6 @@ class File {
parse(columns) {
const stream = new PassThrough();
const fileStream = fs.createWriteStream(this.generatedpath);
stream.pipe(fileStream);
// check if columns is valid
if (!columns || !columns.length) {
@ -165,25 +164,27 @@ class File {
emitter.emit('parse.start', { url: this.url, filepath: this.filepath, headers, result: result });
stream.write(result.join(';') + "\n");
fileStream.write(result.join(';') + "\n");
})
.on('data', (row) => {
// Emit a parse.data event with the url, filepath and data
let result = this.processRow(row, columnsIndex, columnsFiltered);
emitter.emit('parse.data', { url: this.url, filepath: this.filepath, data: row, result, index: count });
stream.write(result.join(';') + "\n");
fileStream.write(result.join(';') + "\n");
count++;
})
.on('error', (err) => {
// Emit a parse.error event with the error
emitter.emit('parse.error', { url: this.url, filepath: this.filepath, error: err.message });
fileStream.end();
fileStream.close();
fs.unlink(this.generatedpath, () => {});
})
.on('end', () => {
// Emit a parse.end event with the url and filepath
stream.end();
fileStream.end();
fileStream.close();
emitter.emit('parse.end', { url: this.url, filepath: this.filepath, count: count - 1, generated: path.basename(this.generatedpath) });
});

Loading…
Cancel
Save