Below is my code where I am trying to use fs.createReadStream that is piped into a fs.createWriteStream. Its working for one hit. But if I run the same code using concurrent hits getting error as
Error: ENOENT, no such file or directory
var fileReadStream = fs.createReadStream("test.png", {encoding: "utf16le"});
var fileWriteStream = fs.createWriteStream("test1.png", {encoding: "utf16le"});
fileReadStream.pipe(fileWriteStream);
fileReadStream.on('end', function () {
});
fileWriteStream.on('close', function () {
fileReadStream.on('finish', function () {
fs.unlink(test1.png);
})
})
I am not that good in filesystem api's. Can someone help me what I am doing wrong here.
The fs. createWriteStream(path, [options]) method returns a writable stream object for file at path . The following options are available: flags : File mode argument as a string.
createWriteStream() in append mode overwrites files on Windows #1897.
pipe() method in a Readable Stream is used to attach a Writable stream to the readable stream so that it consequently switches into flowing mode and then pushes all the data that it has to the attached Writable. Syntax: readable.pipe( destination, options )
Add __dirname + '/test.png' that fixed my error
var fileReadStream = fs.createReadStream(__dirname + <path to image From current directory>, {encoding: "utf16le"});
var fileWriteStream = fs.createWriteStream(__dirname + <path to image From current directory>, {encoding: "utf16le"});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With