Class Mongo::Grid::FSBucket::Stream::Write
In: lib/mongo/grid/stream/write.rb
Parent: Object

A stream that writes files to the FSBucket.

@since 2.1.0

Methods

abort   close   closed?   new   write   write_concern  

Attributes

file_id  [R]  @return [ Object ] file_id The id of the file being uploaded.

@since 2.1.0

filename  [R]  @return [ String ] filename The name of the file being uploaded.

@since 2.1.0

fs  [R]  @return [ FSBucket ] fs The fs bucket to which this stream writes.

@since 2.1.0

options  [R]  @return [ Hash ] options The write stream options.

@since 2.1.0

Public Class methods

Create a stream for writing files to the FSBucket.

@example Create the stream.

  Stream::Write.new(fs, options)

@param [ FSBucket ] fs The GridFS bucket object. @param [ Hash ] options The write stream options.

@option opts [ Object ] :file_id The file id. An ObjectId is generated otherwise. @option opts [ Integer ] :chunk_size Override the default chunk size. @option opts [ Hash ] :write The write concern. @option opts [ Hash ] :metadata User data for the ‘metadata’ field of the files collection document. @option opts [ String ] :content_type The content type of the file.

  Deprecated, please use the metadata document instead.

@option opts [ Array<String> ] :aliases A list of aliases.

  Deprecated, please use the metadata document instead.

@since 2.1.0

Public Instance methods

Abort the upload by deleting all chunks already inserted.

@example Abort the write operation.

  stream.abort

@return [ true ] True if the operation was aborted and the stream is closed.

@since 2.1.0

Close the write stream.

@example Close the stream.

  stream.close

@return [ BSON::ObjectId, Object ] The file id.

@raise [ Error::ClosedStream ] If the stream is already closed.

@since 2.1.0

Is the stream closed.

@example Is the stream closed.

  stream.closed?

@return [ true, false ] Whether the stream is closed.

@since 2.1.0

Write to the GridFS bucket from the source stream.

@example Write to GridFS.

  stream.write(io)

@param [ IO ] io The source io stream to upload from.

@return [ Stream::Write ] self The write stream itself.

@since 2.1.0

Get the write concern used when uploading.

@example Get the write concern.

  stream.write_concern

@return [ Mongo::WriteConcern ] The write concern.

@since 2.1.0

[Validate]