From ae34dcfd3823a609ba7182f2d6eda593be876f7d Mon Sep 17 00:00:00 2001 From: Arman Shah Date: Mon, 19 Feb 2018 23:50:04 -0800 Subject: add base files --- node_modules/stringstream/example.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 node_modules/stringstream/example.js (limited to 'node_modules/stringstream/example.js') diff --git a/node_modules/stringstream/example.js b/node_modules/stringstream/example.js new file mode 100644 index 0000000..f82b85e --- /dev/null +++ b/node_modules/stringstream/example.js @@ -0,0 +1,27 @@ +var fs = require('fs') +var zlib = require('zlib') +var strs = require('stringstream') + +var utf8Stream = fs.createReadStream('massiveLogFile.gz') + .pipe(zlib.createGunzip()) + .pipe(strs('utf8')) + +utf8Stream.pipe(process.stdout) + +// Stream from utf8 to hex to base64... Why not, ay. +var hex64Stream = fs.createReadStream('myFile') + .pipe(strs('utf8', 'hex')) + .pipe(strs('hex', 'base64')) + +hex64Stream.pipe(process.stdout) + +// Deals with base64 correctly by aligning chunks +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')) +}) -- cgit v1.2.3