MongoDB Driver API for Node.js (original) (raw)
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 |
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
error
An error occurred
Type:
- Error
finish
end()
was called and the write stream successfully wrote the file
metadata and all the chunks to MongoDB.
Type:
- object