Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

split2

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

split2

split a Text Stream into a Line Stream, using Stream 2

  • 0.2.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is split2?

The split2 npm package is a Node.js module that allows you to split a stream of text into lines, handling backpressure correctly. It's particularly useful for reading and processing large text files or logs line by line without loading the entire file into memory. This can significantly improve performance and efficiency when dealing with large datasets or streams.

What are split2's main functionalities?

Splitting a stream into lines

This feature allows you to read a file stream and split it into lines. Each line is then processed individually, which is useful for parsing logs or any line-based data.

"use strict";
const split2 = require('split2');
const fs = require('fs');

fs.createReadStream('file.txt')
  .pipe(split2())
  .on('data', function (line) {
    console.log(line);
  });

Using a custom matcher

This demonstrates how to use a custom regular expression as a matcher to split the stream. This is useful when lines are not just separated by a newline character but could include carriage returns or other variations.

"use strict";
const split2 = require('split2');

process.stdin
  .pipe(split2(/(?:\r\n|\r|\n)/g))
  .on('data', function (line) {
    console.log('Line:', line);
  });

Other packages similar to split2

FAQs

Package last updated on 12 Aug 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc