Buffer and validate a readable stream.
Buffers a readable stream and validates its length. This can be considered a streams2 version of concat-stream with validation.
You may also be interested in:
var cat = require'cat-stream'var stream = fscreateReadStream'some file.txt'streampipecat
Creates a duplex stream.
You must pipe the readable stream into
The options are:
expect(also aliased as
expectedLength) - Either an integer in bytes of the expected content length or
true, will check for
source.headers['content-length']. If the expected length does not match the resulting buffer, it will return a
err.key === 'length-mismatch'error.
limit- An integer in bytes of the maximum resulting buffer size. If the incoming data exceeds this limit, it will return a `err.key === 'length-exceeded' error.
passError- will pass any errors from the source stream to
cat. Not necessary if you use domains and don't care to continue logic.
passClose- will pass any
closeevents from the source stream to
cat. Not necessary if you don't care to continue logic.
callback(err, buf) is an optional callback.
It simplifies the stream API and allows for only one exit.
buf is the resulting buffer,
cat was destroyed, it will be
passClose: true and never
cat().destroy() if you don't want to bother to check
You can retrieve the buffer the streams2 way by listening to the readable event:
streampipecaton'readable'var buf = thisread1
but you should also listen to the
error event as well.
This is annoying, thus the
cat assumes the source stream is a binary stream.
cat will never support any other type of stream,
so please don't do anything like this:
Instead, you should do this:
streampipecatvar string = buftoString'utf8'
The MIT License (MIT)
Copyright (c) 2013 Jonathan Ong email@example.com
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.