7

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.

user4324324
  • 559
  • 3
  • 7
  • 25
  • Please look at http://stackoverflow.com/questions/12906694/fs-createwritestream-does-not-immediately-create-file – Olivercodes Oct 13 '15 at 13:07
  • 2
    also be sure that your paths are correct, if you are missing a folder you will get this error. – TlonXP Dec 22 '15 at 03:40
  • 2
    I am encountering the same problem. I've narrowed it down to `fs.createWriteStream(path)` as the cause. `path` is correct, and the file and its parent folders all exist. After some seconds, the write stream emits an `ENOENT` error. This is extra confusing because this has worked elsewhere in the code. – Terra Ashley Aug 16 '16 at 03:12

1 Answers1

3

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"});