new GridFSBucketReadStream(chunks, files, readPreference, filter, options)
A readable stream that enables you to read buffers from GridFS.
Do not instantiate this class directly. Use openDownloadStream()
instead.
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
chunks |
Collection |
Handle for chunks collection |
|||||||||||||||
files |
Collection |
Handle for files collection |
|||||||||||||||
readPreference |
Object |
The read preference to use |
|||||||||||||||
filter |
Object |
The query to use to find the file document |
|||||||||||||||
options |
Object |
optional
Optional settings.
|
Fires:
Extends
Methods
-
abort(callback)
-
Marks this stream as aborted (will never push another
data
event)
and kills the underlying cursor. Will emit the 'end' event, and then
the 'close' event once the cursor is successfully killed.Name Type Description callback
GridFSBucket~errorCallback optional called when the cursor is successfully closed or an error occurred.
Fires:
- GridFSBucketWriteStream#event:close
- GridFSBucketWriteStream#event:end
-
Sets the 0-based offset in bytes to start streaming from. Throws
an error if this stream has entered flowing mode
(e.g. if you've already calledon('data')
)Name Type Description end
Number Offset in bytes to stop reading at
Returns:
to self
-
inherited pause(){null}
-
This method will cause a stream in flowing-mode to stop emitting data events. Any data that becomes available will remain in the internal buffer.
-
inherited pipe(destination, options){null}
-
This method pulls all the data out of a readable stream, and writes it to the supplied destination, automatically managing the flow so that the destination is not overwhelmed by a fast readable stream.
Name Type Description destination
Writable The destination for writing data
options
object optional Pipe options
-
inherited read(size){String|Buffer|null}
-
The read() method pulls some data out of the internal buffer and returns it. If there is no data available, then it will return null.
Name Type Description size
number Optional argument to specify how much data to read.
-
inherited resume(){null}
-
This method will cause the readable stream to resume emitting data events.
-
inherited setEncoding(encoding){null}
-
Call this function to cause the stream to return strings of the specified encoding instead of Buffer objects.
Name Type Description encoding
string The encoding to use.
-
start(start){GridFSBucketReadStream}
-
Sets the 0-based offset in bytes to start streaming from. Throws
an error if this stream has entered flowing mode
(e.g. if you've already calledon('data')
)Name Type Description start
Number Offset in bytes to start reading at
Returns:
to Self
-
inherited unpipe(destination){null}
-
This method will remove the hooks set up for a previous pipe() call.
Name Type Description destination
Writable optional The destination for writing data
-
inherited unshift(chunk){null}
-
This is useful in certain cases where a stream is being consumed by a parser, which needs to "un-consume" some data that it has optimistically pulled out of the source, so that the stream can be passed on to some other party.
Name Type Description chunk
Buffer | string Chunk of data to unshift onto the read queue.
-
inherited wrap(stream){null}
-
Versions of Node prior to v0.10 had streams that did not implement the entire Streams API as it is today. (See "Compatibility" below for more information.)
Name Type Description stream
Stream An "old style" readable stream.
Events
-
Fired when the stream is exhausted and the underlying cursor is killed
Type:
- object
-
Emitted when a chunk of data is available to be consumed.
Type:
- object
-
Fired when the stream is exhausted (no more data events).
Type:
- object
-
An error occurred
Type:
- Error
-
Fires when the stream loaded the file document corresponding to the
provided id.Type:
- object