Utilizing Typescript and libuv
for IO operations is crucial. In my current situation, I am generating a fingerprint hash of a particular file. Let's say the input file size is approximately 1TB. To obtain the file's fingerprint, one method involves opening the file via a stream and updating the hash:
return new Promise((resolve, reject) => {
const hash = crypto.createHash('sha256');
const fh = fse.createReadStream(filepath, {
highWaterMark : 100000000
});
fh.on('data', (d) => { hash.update(d); });
fh.on('end', () => {
resolve(hash);
});
fh.on('error', reject);
});
This sequential process may be slow. Therefore, an alternative faster approach could be dividing the calculation into N blocks as demonstrated below:
let promises = [];
for (let i = 0; i < N; ++i) {
promises.push(calculateFilePart(file, from, to));
}
return Promise.all(all);
If we consider N
to be 1000000 in the scenario provided, would libuv
initiate 1000000 asynchronous I/O operations simultaneously? Or does libuv manage them by queuing automatically in batches to prevent an overflow of IO requests?
I would greatly appreciate any assistance on this matter!