Giter Club home page Giter Club logo

split-stream's Introduction

split-stream Build Status

stream of split strings

Installation

$ npm install split-stream

Usage

var fs = require('fs'),
    splitStream = require('split-stream'),
    ss = splitStream.create();

fs.createReadStream('./file').pipe(ss).pipe(process.stdout);

stream2

var fs = require('fs'),
    splitStream = require('split-stream').SplitStream2,
    ss = splitStream.create();

ss.on('readable', function() {
  var buf;

  while ((buf = ss.read(1)) !== null) {
    console.log(buf);
  }
});
ss.on('end', function() {
  console.log('end');
});

fs.createReadStream('./index.js').pipe(ss);

old-style stream

var fs = require('fs'),
    splitStream = require('split-stream').SplitStream1,
    ss = splitStream.create({
      splitStr: '\t'
    });

ss.setEncoding('utf8');

ss.on('data', function(data) {
  console.log(data);
});
ss.on('end', function() {
  ss.destory();
});
ss.on('close', function() {
  console.log('close');
});

fs.createReadStream('./file').pipe(ss);

Class

SplitStream

class of SplitStream1 or SplitStream2.

var splitStream = require('split-stream');

// true if over version 0.9.
(splitStream === splitStream.SplitStream2);

// true if over version 0.8.
(splitStream === splitStream.SplitStream2);

SplitStream2

inherited stream2 class.

Function (SplitStream2)

create(options)

  • `` object - options object

  • return SplitStream2 - SplitStream2

throw TypeError if options.splitStr is not string or regexp types.

objectMode and decodeStrings are always true.

options

  • splitStr string or regexp - split string

default value is /\r?\n/.

  • encoding string - encoding

default value is utf8. this value is argument of string_decoder.

SplitStream1

inherited old-style stream class.

Function (SplitStream1)

create(options)

  • options object - option object

  • return SplitStream1 - SplitStream1

throw TypeError if options.splitStr is not string or regexp types.

options

  • splitStr string or regexp - split string

default value is /\r?\n/.

Events (SplitStream1)

close

called destroy().

data

  • data string - split string

until buffer is empty.

drain

when buffer is empty.

end

call after end() and when buffer is empty.

error

  • error Error - error object

call twice destory() or call write() after end().

Test

$ npm install
$ npm test

License

The MIT License. Please see LICENSE file.

split-stream's People

Contributors

sasaplus1 avatar

Watchers

Jean-Luc Canela avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.