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

bsplit2

v1.0.2

Published

A binary transform stream splitting chunks by newline characters

Downloads

166

Readme

bsplit2

NPM

A transform stream that splits incoming data into newline separated chunks.

Similar to split2 but only operates on the binary data, doesn't do a string conversion, and only looks for \n in the incoming stream. Use split2 if you want to break on /\r?\n/ or if you're concerned that \n may not properly indicate newlines (e.g. unicode codepoints that include \n bytes).

Not similar and no relation to the "bsplit" package.

API

const bsplit = require('bsplit2')
const splittingStream = bsplit()
// ... pipe something through splittingStream ...

Example

example.js:

const fs = require('fs')
const bsplit = require('bsplit')

let i = 1
fs.createReadStream(__filename)
  .pipe(bsplit())
  .on('data', (line) => console.log(`${i++}: ${line.toString()}`))

When run, will output:

1: const fs = require('fs')
2: const bsplit = require('bsplit2')
3: 
4: let i = 1
5: fs.createReadStream(__filename)
6:   .pipe(bsplit())
7:   .on('data', (line) => console.log(`${i++}: ${line.toString()}`))

Or if you want to use a stream as an async iterator:

const fs = require('fs')
const bsplit = require('bsplit2')

async function run () {
  let i = 1
  const stream = fs.createReadStream(__filename).pipe(bsplit())

  for await (const line of stream) {
    console.log(`${i++}: ${line.toString()}`)
  }
}

run().catch((err) => {
  console.error(err.stack)
  process.exit(1)
})

When run, will output:

1: const fs = require('fs')
2: const bsplit = require('bsplit2')
3: 
4: async function run () {
5:   let i = 1
6:   const stream = fs.createReadStream(__filename).pipe(bsplit())
7: 
8:   for await (const line of stream) {
9: 	  console.log(`${i++}: ${line.toString()}`)
10:   }
11: }
12: 
13: run().catch((err) => {
14:   console.error(err.stack)
15:   process.exit(1)
16: })

bsplit2's readable streams are "object mode" meaning that they apply different backpressure rules even though they are still dealing with binary data. This may be an important consideration depending on your use-case. This can be turned off by messing with stream._readableState.objectMode (not recommended) but the internal stream read() function will revert back to providing non-newline-delimited chunks because it pulls from a buffer of chunks. This impacts async iterators and some other stream modes but the 'data' event won't be impacted although it will drop blank lines.

Licence & Copyright

Copyright 2019 Rod Vagg

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.