Class: GridFSBucketWriteStream

GridFSBucketWriteStream

new GridFSBucketWriteStream(bucket, filename, options){GridFSBucketWriteStream}

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 optional

The write concern

wtimeout number optional

The write concern timeout

j number optional

The journal write concern

disableMD5 boolean false optional

If true, disables adding an md5 field to file data

Fires:
Returns:
GridFSBucketWriteStream instance.

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 function

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 function

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