file-chunk-processor
v0.0.1
Published
Reads a file in sections and allows an operation to be performed on each chunk of data.
Downloads
31
Readme
File chunk processing
Reads through a file and every 'x' bytes of the file, runs a processing function to do something with the chunk that has been read.
Could be used for uploading a file in chunks for example.
The callback function is specified in the form
function (dataReadBuffer, chunkIndex, bytesRead, totalFileSize) {...}
Installation
npm install --save file-chunk-processor
Usage
const fp = require('file-chunk-processor');
const config = {
filePath: 'bigvideo.mp4',
chunkSize: 1024 * 1024 * 2, // 2 mb
processingFunc: (dataReadBuffer, chunkIndex, bytesRead, totalFileSize) => {
// do something with data in buffer
}
};
fp.processFile(config)
.then(() => {
// Do something when file has been processed.
})
.catch(err => {...});
Testing
npm test