[ad_1]
I am a newbie in javascript so I’m still having many issues that I still don’t get it. I’m using this module ‘split-file-stream’ https://www.npmjs.com/package/split-file-stream and this code particularly:
var splitFileStream = require("split-file-stream");
let maxFileSize = 1024; // 1024 bytes per file
let outputPath = __dirname + "/outputFiles"; // file path partition's prefix
var customSplit = splitFileStream.getSplitWithGenFilePath((n) => `${outputPath}-${(n + 1)}`)
customSplit(readStream, maxFileSize, (error, filePaths) => {
/* If an error occured, filePaths will still contain all files that were written */
if (error) throw error; // Alternatively you could just log the error instead of throwing: if (error) console.error(error)
console.log("This is an array of my new files:", filePaths);
});
if I’m correct, I understand that fs.createReadStream is asynchronous. But what I need is that the file splitting makes it synchronous way. This is because after creating the parts, I’m going to use the splitting parts for some other stuff. But I cannot do that because when I want access to the files, these ones don’t exist yet. The question is whether a way to make this code synchronous.
PD: I’ve using Promises (async/await) but I don’t know if I am using them wrong because doesn’t wait.
[ad_2]