1 # Decode streams into strings The Right Way(tm)
5 var zlib = require('zlib')
6 var strs = require('stringstream')
8 var utf8Stream = fs.createReadStream('massiveLogFile.gz')
9 .pipe(zlib.createGunzip())
13 No need to deal with `setEncoding()` weirdness, just compose streams
14 like they were supposed to be!
16 Handles input and output encoding:
19 // Stream from utf8 to hex to base64... Why not, ay.
20 var hex64Stream = fs.createReadStream('myFile')
21 .pipe(strs('utf8', 'hex'))
22 .pipe(strs('hex', 'base64'))
25 Also deals with `base64` output correctly by aligning each emitted data
26 chunk so that there are no dangling `=` characters:
29 var stream = fs.createReadStream('myFile').pipe(strs('base64'))
33 stream.on('data', function(data) { base64Str += data })
34 stream.on('end', function() {
35 console.log('My base64 encoded file is: ' + base64Str) // Wouldn't work with setEncoding()
36 console.log('Original file is: ' + new Buffer(base64Str, 'base64'))