ProductPromotion
Logo

Node.JS

made by https://0x3d.site

GitHub - jahewson/node-byline: Line-by-line Stream reader for node.js
Line-by-line Stream reader for node.js. Contribute to jahewson/node-byline development by creating an account on GitHub.
Visit Site

GitHub - jahewson/node-byline: Line-by-line Stream reader for node.js

GitHub - jahewson/node-byline: Line-by-line Stream reader for node.js

byline — buffered stream for reading lines

npm package

byline is a simple module providing a LineStream.

  • node v0.10 streams2 (transform stream)
  • supports pipe
  • supports both UNIX and Windows line endings
  • supports Unicode UTS #18 line boundaries
  • can wrap any readable stream
  • can be used as a readable-writable "through-stream" (transform stream)
  • super-simple: stream = byline(stream);

Install

npm install byline

or from source:

git clone git://github.com/jahewson/node-byline.git
cd node-byline
npm link

Convenience API

The byline module can be used as a function to quickly wrap a readable stream:

var fs = require('fs'),
    byline = require('byline');

var stream = byline(fs.createReadStream('sample.txt', { encoding: 'utf8' }));

The data event then emits lines:

stream.on('data', function(line) {
  console.log(line);
});

Standard API

You just need to add one line to wrap your readable Stream with a LineStream.

var fs = require('fs'),	
    byline = require('byline');

var stream = fs.createReadStream('sample.txt');
stream = byline.createStream(stream);

stream.on('data', function(line) {
  console.log(line);
});

Piping

byline supports pipe (though it strips the line endings, of course).

var stream = fs.createReadStream('sample.txt');
stream = byline.createStream(stream);
stream.pipe(fs.createWriteStream('nolines.txt'));

Alternatively, you can create a readable/writable "through-stream" which doesn't wrap any specific stream:

var stream = fs.createReadStream('sample.txt');
stream = byline.createStream(stream);
stream.pipe(fs.createWriteStream('nolines.txt'));
	
var input = fs.createReadStream('LICENSE');
var lineStream = byline.createStream();
input.pipe(lineStream);

var output = fs.createWriteStream('test.txt');
lineStream.pipe(output);

Streams2 API

Node v0.10 added a new streams2 API. This allows the stream to be used in non-flowing mode and is preferred over the legacy pause() and resume() methods.

var stream = fs.createReadStream('sample.txt');
stream = byline.createStream(stream);

stream.on('readable', function() {
  var line;
  while (null !== (line = stream.read())) {
    console.log(line);
  }
});

Transform Stream

The byline transform stream can be directly manipulated like so:

var LineStream = require('byline').LineStream;

var input = fs.createReadStream('sample.txt');
var output = fs.createWriteStream('nolines.txt');

var lineStream = new LineStream();
input.pipe(lineStream);
lineStream.pipe(output);

Empty Lines

By default byline skips empty lines, if you want to keep them, pass the keepEmptyLines option in the call to byline.createStream(stream, options) or byline(stream, options).

Tests

npm test

v0.8

If you want to use node-byline with node v0.8 then you can use the 2.1.x series. Simply use the following in your package.json:

  "dependencies": {
  "byline": ">=2.1.0 <3.0.0"
},

Simple

Unlike other modules (of which there are many), byline contains no:

  • monkeypatching
  • dependencies
  • non-standard 'line' events which break pipe
  • limitations to only file streams
  • CoffeeScript
  • unnecessary code

Articles
to learn more about the nodejs concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about NodeJS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory