I want to upload a big file by using node js,but the node js using aync mode,How do I upload the big file by block.My code looks like this:
var i = 0;
while(i < myObj.filesize){
fs.readSync(in_fd, buf, 0, myObj.blockSize, null);
i += myObj.blockSize;
sendfile(buf); //the sendfile send data in aync mode
}
The best way to what you want is to use a readable stream and a writable one:
fs.createReadStream('path/to/file').pipe(destinationStream);