Basically what I'm trying to do is Write to my file from an external source, Read from that file and then re-Write to it with some updated style. I'm doing this to an image. Ex code:
var rawImg = urlHtml('img').attr('src'); // got the image from a website!
var wStream = request(rawImg).pipe(fs.createWriteStream(__dirname + '/public/img/test.jpg')); //write img to file
var rStream = fs.createReadStream(__dirname + '/public/img/test.jpg', {encoding: 'base64'}); // read img from file
var wStream2 = fs.createWriteStream(__dirname + '/public/img/test-result.jpg') // output
The image does save to file, but anytime I try to read it I always get the error: { [Error: spawn ENOENT] code: 'ENOENT', errno: 'ENOENT', syscall: 'spawn' } - which means its not even there yet
You're trying to read the file before it has been created. Try waiting for the file to be closed first:
var wStream = request(rawImg).pipe(fs.createWriteStream(__dirname + '/public/img/test.jpg'));
wStream.on('close', function() {
var rStream = fs.createReadStream(__dirname + '/public/img/test.jpg', {encoding: 'base64'});
var wStream2 = fs.createWriteStream(__dirname + '/public/img/test-result.jpg');
});