wolf-textstream
v0.0.1
Published
A readable stream implementation for string and text files.
Downloads
10
Readme
wolf-textstream
A readable stream implementation for string and text files.
Introduction
Wolf-TextStream is an implementation of node's stream.Readable specification. I developed this module personally to write some unit tests where I need to emulate reading from file, but I don't have an actual file. Hence, I thought to develop an Readable implementation that can accept a string as constructor parameter that mimic like a file content.
The Wolf-TextStream supports not just a string, but a file descriptor or another readable file stream itself.
Installation
$ npm install --save wolf-textstream
Usage
Use a string as source of stream
let textSource = 'Hello, World';
let stream = new WolfTextstream(textSource);
let textData = stream.read().toString();
Use an another readable stream as source of stream
let fileStream = fs.createReadStream(fileName);
let stream = new WolfTextstream(fileStream);
stream.on('data', (data) => {
data = data.toString();
data.should.equal(textData);
});
Use file descriptor as source of stream
let fd = fs.openSync(fileName, 'r');
let stream = new WolfTextstream(fd);
let data = stream.read();
data = data.toString();
License
MIT © Benoy Bose