npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

splitly

v1.0.2

Published

Split a stream on a new-line character and reassemble it into a stream of line-sized chunks. Zero dependencies with a focus on speed and simplicity.

Downloads

8

Readme

GitHub Workflow Status Apache License Dependencies

Splitly

Splits a stream on a new-line character and reassemble it into a stream of line-sized chunks. Zero dependencies with a focus on speed and simplicity.

There are a number of alternatives our there, namely split, binary-split and split2. All of which are significantly slower than this implementation and some have additional dependencies. Splitly extends stream.Duplex instead of stream.Transform for greater control over memory pressure and speed.

const splitly = require('splitly');

fs.createReadStream(file)
  .pipe(splitly.createStream())
  .on('data', function (line) {
    // each chunk is a separate line
    // chunks are buffers and are not stripped of the newline character(s)
    const trimmed = line.toString().trim();
  });

Note: Usage of the data event is not recommended in production code and should only be used for strictly synchronous/blocking code. Instead, pipe the output of the stream to another stream capable of propagating back pressure (such as process.stdout or a stream that writes to a database or makes an API call).

splitly requires the newline character(s) to be defined as a Buffer, unlike other split stream implementations which also accept regular expressions. Additionally, the newline character is not truncated from the chunk passed to the data event. The default newline character is \n. If you want to split on /\r?\n/ instead, keep the default newline character and trim() the chunk in the data callback.

API

createStream({ newlineChar: Buffer }, DuplexOptions )

  • newlineChar <Buffer> Default: Buffer.from('\n')
  • DuplexOptions <Object> Default: {} passed to stream.Duplex constructor

Custom Newline Character

const splitly = require('splitly');

const stream = splitly.createStream({
  // split on zero-byte delimited lines, must be provided as Buffer
  newlineChar: Buffer.from('\0'),
});

Benchmark

/dev/null is the raw performance of piping the test stream to /dev/null. This is the lower boundary of the performance that can be achieved. It also makes sure the file is in the OS file cache. See ./benchmark/index.js for details. Run under NodeJS v14.18.3.

| name | time | stdev | | -- | -- | -- | | /dev/null | 5.41 | 2.67 | | splitly | 10.35 | 4.91 | | split2 | 34.24 | 3.04 | | split | 34.71 | 4.78 | | byline | 39.55 | 13.72 | | binary-split | 46.55 | 9.22 |