eob
v1.0.2
Published
Ready-to-pipe stream to glue and slice a chunked stream. Includes handshaking!
Downloads
2
Maintainers
Readme
eob (end of block) is a tiny module to glue and slice a chunked stream. It includes a simplest-possible handshake validation.
Installation
npm install eob
Usage
Just pipe a new EOB stream to your chunked stream.
stream.pipe(require('eob')(eob, handshake))
Handshaking
You can specify a handshake (Buffer
or String
type). If handshake is not completed the EOB stream will emit a finish
event. By default, the EOB character is \n
.
Example
const Stream = require('stream');
const eobFactory = require('eob');
let stream, pipe;
stream = new Stream();
stream.readable = true;
stream.writable = true;
stream.end = stream.emit.bind(stream, 'end');
stream.read = stream.emit.bind(stream, 'read');
stream.write = stream.emit.bind(stream, 'data');
pipe = stream.pipe(eobFactory('\n', 'GabbaGabbaHey:'));
pipe.on('data', function(d) { console.log(d.toString()) })
stream.write('GabbaGabbaHey:Hey\nHo\nLet\'s go!\n');
License
The MIT License (MIT) Copyright (c) 2016 Manuel de la Higuera
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.