Git Product home page Git Product logo

node-binary-split's Introduction

Binary Split

GitHub stars npm version Build Coverage Status Known Vulnerabilities License: MIT

A Transform Stream that splits a binary stream into chunks based on a delimiter. The delimiter can be a String or a Buffer.

Install

npm install node-binary-split --save

Usage

import split from 'node-binary-split';

split(delimiter);

or

import { BinarySplit } from 'node-binary-split';

new BinarySplit(delimiter);

delimiter can be a string or a buffer.

Sample

import {BinarySplit } = from 'node-binary-split';
fs.createReadStream(file)
  .pipe(new BinarySplit('\n'))
  .on('data', function(line) {
    //each chunk now is a separate line!
  });
const split = require('node-binary-split');
fs.createReadStream(file)
  .pipe(split('\n'))
  .on('data', function (line) {
    //each chunk now is a separate line!
  });

Benchmarks

Benchmarking node-binary-split against other similar packages with benchmark.js. One with newline as delimiter and one with a longer string

Split on a string:

node-binary-split x 1,368 ops/sec ±3.68% (70 runs sampled)
binary-split x 773 ops/sec ±2.75% (74 runs sampled)
split x 504 ops/sec ±2.02% (75 runs sampled)
split2 x 486 ops/sec ±1.95% (75 runs sampled)
Fastest is node-binary-split
Split on newline:

node-binary-split x 1,682 ops/sec ±3.51% (72 runs sampled)
binary-split x 472 ops/sec ±2.68% (76 runs sampled)
split x 574 ops/sec ±3.34% (73 runs sampled)
split2 x 477 ops/sec ±2.51% (77 runs sampled)
Fastest is node-binary-split

Development

Test

Run tests by:

npm test

Run benchmarks by:

npm run bench

Support

Submit an issue

Contribute

Contribute usage docs

License

MIT License

Simen Haugerud Granlund © 2019

Credits

node-binary-split's People

Contributors

hgranlund avatar dependabot[bot] avatar reinaldoacdc avatar

Stargazers

Michael Sageryd avatar  avatar Reinaldo Costa avatar Teodor Elstad avatar mok-liee avatar Max Stern avatar

Watchers

James Cloos avatar  avatar

node-binary-split's Issues

Delimiter splitted in different chunks.

Hi =)
First of all, Thanks for this Awesome lib, it helped me a lot.

I used it so much that I've found an issue.

Sometimes happens that my delimiter is splitted by the incoming stream.
So, I have a situation like:

Delimiter = --CUSTOM--

Chunk 1 - 
AAA--CUST


Chunk 2 - 
OM--BBB

As the delimiter is spplited, the transform function doesn’t threat it right.

So I created and pending buffer to aggregate the chunks and split at this splitted delimiter correctly.
I'm gonna open an PR to demonstrate it.

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.