Skip to content

Instantly share code, notes, and snippets.

@bryanmacfarlane
Last active August 29, 2015 14:16
Show Gist options
  • Save bryanmacfarlane/cbf864336bc9b6ad6884 to your computer and use it in GitHub Desktop.
Save bryanmacfarlane/cbf864336bc9b6ad6884 to your computer and use it in GitHub Desktop.
Node v0.12 Stream Bug
var path = require('path');
var stream = require('stream');
var fs = require('fs');
var PassThrough = require('stream').PassThrough;
var streamThrough = function(filePath, done) {
var len = 0;
var inputStream = fs.createReadStream(filePath);
var ps = new PassThrough();
inputStream.on('error', function (err) {
done(err, len);
});
inputStream.on('end', function () {
done(null, len);
});
inputStream.on('data', function (chunk) {
process.stdout.write('.');
len += chunk.length;
});
inputStream.pipe(ps);
}
var fileArg = process.argv[2];
if (!fileArg) {
console.error('pass file as arg');
process.exit(1);
}
var filePath = path.resolve(__dirname, fileArg);
streamThrough(filePath, function(err, len) {
if (err) {
console.error(err.message);
}
console.log('size: ' + len);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment