0.2.1 • Published 12 years ago

chunker v0.2.1

Weekly downloads
17
License
-
Repository
github
Last release
12 years ago

CHUNKER

node v0.10.x required.

Split your streams into chunks with an arbitary-length matcher. Explicitly does not consume tokens. Useful for splitting up chunks and passing it to an external parser that expects the split tokens to be there.

API

This module exports a Chunker class. This is simply an instance of a Transform stream so you can pipe things in and it will only output (emit readable) a chunk that has all the content from the start of the first chunk until the specified splitter token (called a matcher inside the codebase)

example.js

var fs = require('fs'), Chunker = require('./index.js');

var chunker = new Chunker({ matcher: 'what ' })
  , input = fs.createReadStream('./input.txt');

chunker.on('readable', function() {
  var chunk;
  while (chunk = chunker.read()) {
    console.log(chunk.toString());
  }
});

process.stdin.pipe(chunker);

output

$ node example.js
do what 
you want to do not what 
you are told to do and do what 
makes you happy and keep away from what 
makes you sad but do what 
you have to do that is what 
resposibility means but do not forget what 
makes your heart tick or you will forgot what 

LICENSE

BSD3 (see LICENSE file)

0.2.1

12 years ago

0.2.0

12 years ago

0.1.2

12 years ago