Skip to content

Instantly share code, notes, and snippets.

@donpark
Created February 1, 2012 09:36
Show Gist options
  • Save donpark/1716164 to your computer and use it in GitHub Desktop.
Save donpark/1716164 to your computer and use it in GitHub Desktop.
Example code for processing Gzipped file in Node.js using node-bufferstream
fs = require('fs')
zlib = require('zlib')
# see: https://github.com/dodo/node-bufferstream
BufferStream = require('bufferstream')
input = fs.createReadStream inputPath,
flags: 'r'
mode: 0666
gunzip = zlib.createGunzip()
# assume output is lines of UTF-8 (i.e. RDF N-Triples)
output = new BufferStream
encoding: 'utf8'
size: 'none'
output.split '\r\n', '\r', '\n'
output.on 'split', (line, token) ->
# line is actually always Buffer despite encoding option
line = line.toString() if typeof line isnt 'string'
console.log line
input.pipe(gunzip).pipe(output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment