Created
February 1, 2012 09:36
-
-
Save donpark/1716164 to your computer and use it in GitHub Desktop.
Example code for processing Gzipped file in Node.js using node-bufferstream
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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