Reputation: 763
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
}
Upvotes: 0
Views: 178
Reputation: 11245
The best way to what you want is to use a readable stream and a writable one:
fs.createReadStream('path/to/file').pipe(destinationStream);
Upvotes: 2