Skip to content

Converts a Node.js readable stream to a Bacon stream that emits lines of text. It is also available as an npm package.

License

Notifications You must be signed in to change notification settings

Maultasche/BaconNodeLineStream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is a package with a function that converts a Node.js readable stream to a Bacon.js stream that emits lines of text. So if the Node.js readable stream contains two lines of text (separated by a '\n' character), the corresponding Bacon stream will emit two events, with each event containing a single line of text.

Installing

Via npm:

npm install --save bacon-node-line-stream

Via yarn:

yarn add bacon-node-line-stream

Using

Here's an example of creating a readable stream from a file and then converting that to a Bacon stream.

const createLineStream = require('bacon-node-line-stream');
const fs = require('fs');

//Create a read stream to read the file
const readStream = fs.createReadStream('textFile.txt');

//Create a bacon line stream
const lineStream = createLineStream(readStream);

//Create an error handler
lineStream.onError(error => console.error(error));

//Output the lines from the text file
lineStream.onValue(line => console.log(line));

Running the Example

After downloading the source, you can run an example which reads from a file and outputs the contents of that file line by line:

yarn fileExample example/textFile.txt

This command runs the example/fileExample.js file and passes it the text file to read from.

You can replace "example/textFile.txt" with any text file. For example, we could output the example source file:

yarn fileExample example/fileExample.js

Running the Tests

After downloading, install the dependencies:

yarn install

Then run the unit tests:

yarn test

License

This package is licensed under the MIT license.

About

Converts a Node.js readable stream to a Bacon stream that emits lines of text. It is also available as an npm package.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published