Last active
August 29, 2015 14:16
-
-
Save bryanmacfarlane/cbf864336bc9b6ad6884 to your computer and use it in GitHub Desktop.
Node v0.12 Stream Bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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