Server IP : 66.29.132.122 / Your IP : 18.225.175.174 Web Server : LiteSpeed System : Linux business142.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : admazpex ( 531) PHP Version : 7.2.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/self/root/opt/alt/alt-nodejs9/root/lib/node_modules/npm/node_modules/request/node_modules/stringstream/ |
Upload File : |
# 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')) }) ```