I have used many third-party npm. But I can't pause and resume it. I need to pause the stream while storing data in Mongodb and resume it. I have used fs.createReadStream(). while using stream I got only arrayBuffer type data so I can't convert or store it in the database. Then I used third-party npm to extract data from xlsx. Here I got data in JSON format but I can't pause and resume in those npm packages. Please help me to resolve it. Code must use low memory.
// I have used fs.createReadStream(). But I can't get in proper format
const fs = require("fs");
const stream = fs.createReadStream("demo.xlsx");
stream.on("data", (data) => {
stream.pause();
console.log(data);
// I got data in arrabuffer format I can't get readable format like json, array ets,.
// database store
// after data stored in db i need to resume it
stream.resume();
});
// and I used xlsx-extract npm but I can't pause and resume while data storing
var XLSX = require('xlsx-extract').XLSX;
new XLSX().extract('path/to/file.xlsx', {sheet_id:1})
.on('sheet', function (sheet) {
console.log('sheet',sheet);
})
.on('row', function (row) {
// want to pause it
console.log('row', row);
// want to resume it
})
.on('error', function (err) {
console.error('error', err);
})
.on('end', function (err) {
console.log('eof');
});