Created
December 15, 2022 21:26
-
-
Save YuriFontella/888eb05cc991f3bc2060de166f00a9aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const xlsx = require('xlsx') | |
const { Writable, Transform } = require('stream') | |
const fs = require('fs') | |
const path = require('path') | |
console.log('início') | |
const workbook = xlsx.readFile('data-600.xlsx', { sheetStubs: true }) | |
const sheet_name_list = workbook.SheetNames | |
const readableStreamFile = xlsx.stream.to_json(workbook.Sheets[sheet_name_list[0]], { raw: false }) | |
const transformToString = new Transform({ | |
writableObjectMode: true, | |
transform(chunk, encoding, callback) { | |
callback(null, JSON.stringify(chunk)) | |
} | |
}) | |
const writableStreamFile = new Writable({ | |
write(chunk, encoding, next) { | |
const stringifyer = chunk.toString() | |
const rowData = JSON.parse(stringifyer) | |
fs.appendFileSync(path.resolve('data.log'), JSON.stringify(rowData) + '\n') | |
next() | |
}, | |
}) | |
console.log('Iniciou', Date()) | |
readableStreamFile | |
.pipe(transformToString) | |
.pipe(writableStreamFile) | |
.on('close', () => console.log('Finalizou', Date())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment