Class: GridFSBucketWriteStream

GridFSBucketWriteStream

new GridFSBucketWriteStream(bucket, filename, options)

A writable stream that enables you to write buffers to GridFS.

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

Name Type Description
bucket GridFSBucket

Handle for this stream's corresponding bucket

filename string

The value of the 'filename' key in the files doc

options object optional

Optional settings.

Name Type Default Description
id string | number | object optional

Custom file id for the GridFS file.

chunkSizeBytes number optional

The chunk size to use, in bytes

w number | string optional

Deprecated The write concern. Use writeConcern instead.

wtimeout number optional

Deprecated The write concern timeout. Use writeConcern instead.

j boolean false optional

Deprecated Specify a journal write concern. Use writeConcern instead.

writeConcern object | WriteConcern optional

Specify write concern settings.

disableMD5 boolean false optional

If true, disables adding an md5 field to file data

Fires:

Extends

  • external:Writable

Methods

abort(callback){Promise}

Places this write stream into an aborted state (all future writes fail)
and deletes all chunks that have already been written.

Name Type Description
callback GridFSBucket~errorCallback

called when chunks are successfully removed or error occurred

Returns:
no callback specified

end(chunk, encoding, callback)

Tells the stream that no more data will be coming in. The stream will
persist the remaining data to MongoDB, write the files document, and
then emit a 'finish' event.

Name Type Description
chunk Buffer

Buffer to write

encoding String

Optional encoding for the buffer

callback GridFSBucket~errorCallback

Function to call when all files and chunks have been persisted to MongoDB

write(chunk, encoding, callback){Boolean}

Write a buffer to the stream.

Name Type Description
chunk Buffer

Buffer to write

encoding String

Optional encoding for the buffer

callback GridFSBucket~errorCallback

Function to call when the chunk was added to the buffer, or if the entire chunk was persisted to MongoDB if this chunk caused a flush.

Returns:
if this write required flushing a chunk to MongoDB. True otherwise.

Events

An error occurred

Type:
  • Error

end() was called and the write stream successfully wrote the file
metadata and all the chunks to MongoDB.

Type:
  • object