blob-slicer
v1.0.0
Published
read all or part of the content in a Blob or File as a Buffer or Stream
Downloads
1,133
Maintainers
Readme
blob-slicer
Read all or part of the content in a Blob or File as a Buffer or Stream
Install
npm install blob-slicer
Usage
var BlobSlicer = require('blob-slicer')
var reader = new BlobSlicer(getBlobOrFileSomehow())
// Read as Buffer
reader.read(start, end, function (error, buffer) {
if (error) {
// handle error
}
// handle data
})
// Read as Stream
reader.createReadStream()
.on('data', function (chunk) { ... })
.on('error', function (error) { ... })
.on('end', function () { ... })
blob-slicer depends on buffer v4.x . Therefore, if you are using browserify v14 and higher, you must include buffer v4 instead of the default v5 by either doing :
browserify -r buffer/:buffer main.js -o bundle.js
or
browserify().require(require.resolve('buffer/'), { expose: 'buffer' })
API
Class: BlobSlicer
new BlobSlicer(blob)
Throws error if blob is not an instance of Blob or File.
blobSlicer.read([start], [end], callback)
Read a range of bytes delimited by start(inclusive) and end(exclusive).
If end is not specified, it reads all bytes from start to the end of blob.
If start and end are not specified, it reads all data in the blob.
The callback is passed two arguments (err: Error, buf: Buffer)
.
blobSlicer.createReadStream([options])options
may be omitted, the default is {highWaterMark: 64 * 1024, start: 0, end: blob.size}
.options.start
is inclusive, options.end
is exclusive.
Return an instance of ReadStream
.
Class: ReadStream
An implementation of Readable Streams.
readStream.readableLength: number
same as in stream_readable_readablelength
readStream.ended: booleantrue
if reached the end of blob (there may be still some bytes in the queue ready to be consumed).
License
MIT. Copyright (c) Hoummad Merzouqi.