diff options
| author | Arman Shah <[email protected]> | 2018-02-19 23:50:04 -0800 |
|---|---|---|
| committer | Arman Shah <[email protected]> | 2018-02-19 23:50:04 -0800 |
| commit | ae34dcfd3823a609ba7182f2d6eda593be876f7d (patch) | |
| tree | b9d7f2884c4999349418cbdc4f9ab46d113e0afd /node_modules/stringstream/README.md | |
| parent | Initial commit (diff) | |
| download | launcher-ae34dcfd3823a609ba7182f2d6eda593be876f7d.tar.xz launcher-ae34dcfd3823a609ba7182f2d6eda593be876f7d.zip | |
add base files
Diffstat (limited to 'node_modules/stringstream/README.md')
| -rw-r--r-- | node_modules/stringstream/README.md | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/node_modules/stringstream/README.md b/node_modules/stringstream/README.md new file mode 100644 index 0000000..32fc982 --- /dev/null +++ b/node_modules/stringstream/README.md @@ -0,0 +1,38 @@ +# Decode streams into strings The Right Way(tm) + +```javascript +var fs = require('fs') +var zlib = require('zlib') +var strs = require('stringstream') + +var utf8Stream = fs.createReadStream('massiveLogFile.gz') + .pipe(zlib.createGunzip()) + .pipe(strs('utf8')) +``` + +No need to deal with `setEncoding()` weirdness, just compose streams +like they were supposed to be! + +Handles input and output encoding: + +```javascript +// Stream from utf8 to hex to base64... Why not, ay. +var hex64Stream = fs.createReadStream('myFile') + .pipe(strs('utf8', 'hex')) + .pipe(strs('hex', 'base64')) +``` + +Also deals with `base64` output correctly by aligning each emitted data +chunk so that there are no dangling `=` characters: + +```javascript +var stream = fs.createReadStream('myFile').pipe(strs('base64')) + +var base64Str = '' + +stream.on('data', function(data) { base64Str += data }) +stream.on('end', function() { + console.log('My base64 encoded file is: ' + base64Str) // Wouldn't work with setEncoding() + console.log('Original file is: ' + new Buffer(base64Str, 'base64')) +}) +``` |