"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/stringstream/example.js" (8 Mar 2017, 814 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 var fs   = require('fs')
    2 var zlib = require('zlib')
    3 var strs = require('stringstream')
    4 
    5 var utf8Stream = fs.createReadStream('massiveLogFile.gz')
    6   .pipe(zlib.createGunzip())
    7   .pipe(strs('utf8'))
    8 
    9 utf8Stream.pipe(process.stdout)
   10 
   11 // Stream from utf8 to hex to base64... Why not, ay.
   12 var hex64Stream = fs.createReadStream('myFile')
   13   .pipe(strs('utf8', 'hex'))
   14   .pipe(strs('hex', 'base64'))
   15 
   16 hex64Stream.pipe(process.stdout)
   17 
   18 // Deals with base64 correctly by aligning chunks
   19 var stream = fs.createReadStream('myFile').pipe(strs('base64'))
   20 
   21 var base64Str = ''
   22 
   23 stream.on('data', function(data) { base64Str += data })
   24 stream.on('end', function() {
   25   console.log('My base64 encoded file is: ' + base64Str) // Wouldn't work with setEncoding()
   26   console.log('Original file is: ' + new Buffer(base64Str, 'base64'))
   27 })