Class: GridFSBucketReadStream

GridFSBucketReadStream

new GridFSBucketReadStream(chunks, files, readPreference, filter, options){GridFSBucketReadStream}

A readable stream that enables you to read buffers from GridFS.

Do not instantiate this class directly. Use openDownloadStream() instead.

Name Type Default 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 null optional

Optional settings.

Name Type Default Description
sort Number null optional

Optional sort for the file find query

skip Number null optional

Optional skip for the file find query

start Number null optional

Optional 0-based offset in bytes to start streaming from

end Number null optional

Optional 0-based offset in bytes to stop streaming before

Fires:
Returns:
GridFSBucketReadStream instance.

Methods

Reads from the cursor and pushes to the stream.

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 called on('data'))

Name Type Description
end Number

Offset in bytes to stop reading at

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 called on('data'))

Name Type Description
start Number

Offset in bytes to start reading at

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