Skip to content

Transform stream to read content line-by-line and write a string

License

Notifications You must be signed in to change notification settings

tilfin/readline-transform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ReadlineTransform

npm Node License dependencies Status Build Status Coverage Status

Reading String or Buffer content from a Readable stream and writing each line which ends without line break as object

Install

$ npm install -save readline-transform

How to Use

Create a ReadlineTransform

new ReadlineTransform(options)

  • options <Object>
    • breakMatcher is the regular expression to split content by line break for str.split(). (default: /\r?\n/)
    • ignoreEndOfBreak is boolean. if content ends with line break, ignore last empty line. (default: true)
    • skipEmpty is boolean. if line is empty string, skip it (default: false)

An example

const { PassThrough } = require('stream');
const ReadlineTransform = require('readline-transform');

const readStream = new PassThrough();
const transform = new ReadlineTransform({ skipEmpty: true });
const writeStream = new PassThrough({ objectMode: true });

writeStream.on('data', (line) => {
  console.log(line);
}).on('finish', () => {
  console.log('<<< all done >>>');
});

readStream.pipe(transform).pipe(writeStream);

readStream.write(new Buffer('foo\nba'));
readStream.write(new Buffer('r\r\n\n\r'));
readStream.end(new Buffer('\nbaz'));

Console output

$ node example.js
foo
bar
baz
<<< all done >>>

About

Transform stream to read content line-by-line and write a string

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published