Skip to content

Instantly share code, notes, and snippets.

@paulbjensen
Created October 7, 2013 17:41
Show Gist options
  • Select an option

  • Save paulbjensen/6871896 to your computer and use it in GitHub Desktop.

Select an option

Save paulbjensen/6871896 to your computer and use it in GitHub Desktop.
A script to replicate an issue with stream writing.
'use strict';
// Dependencies
//
var fs = require('fs'),
oldFilePath = 'oldFile.txt',
read = fs.createReadStream(oldFilePath),
write = fs.createWriteStream('./.newFile.txt');
// Generate the oldFile first with some example content
//
fs.writeFile(oldFilePath, 'Example Content to write here\n', function (err) {
if (err) {
throw err;
} else {
// Write the file out
//
read.pipe(write);
}
});
@joates
Copy link

joates commented Oct 7, 2013

this works..

var fs = require('fs')
fs.writeFile('log.txt', "Example Content\n", function (err) {
  if (err) throw err
  fs.createReadStream('./log.txt').pipe(fs.createWriteStream('./.new_log.txt'))
})

@paulbjensen
Copy link
Author

Thanks. I copied that and ran it on my machine, it didn't work. I'm running v0.10.20 on Mac OS X 10.8.5.

@paulbjensen
Copy link
Author

Ignore me. I was using ls -ll to list files, rather than ls -la.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment