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

A stream that reads files from the FSBucket.

@since 2.1.0

Methods

close   closed?   each   file_info   new   read   read_preference  

Included Modules

Enumerable

Attributes

file_id  [R]  @return [ BSON::ObjectId, Object ] file_id The id of the file being read.

@since 2.1.0

fs  [R]  @return [ FSBucket ] fs The fs bucket from which this stream reads.

@since 2.1.0

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

@since 2.1.0

Public Class methods

Create a stream for reading files from the FSBucket.

@example Create the stream.

  Stream::Read.new(fs, options)

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

@since 2.1.0

Public Instance methods

Close the read 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 closd.

  stream.closed?

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

@since 2.1.0

Iterate through chunk data streamed from the FSBucket.

@example Iterate through the chunk data.

  stream.each do |data|
    buffer << data
  end

@return [ Enumerator ] The enumerator.

@raise [ Error::MissingFileChunk ] If a chunk is found out of sequence.

@yieldparam [ Hash ] Each chunk of file data.

@since 2.1.0

Get the files collection file information document for the file being read.

@example Get the file info document.

  stream.file_info

@return [ Hash ] The file info document.

@since 2.1.0

Read all file data.

@example Read the file data.

  stream.read

@return [ String ] The file data.

@raise [ Error::MissingFileChunk ] If a chunk is found out of sequence.

@since 2.1.0

Get the read preference used when streaming.

@example Get the read preference.

  stream.read_preference

@return [ Mongo::ServerSelector ] The read preference.

@since 2.1.0

[Validate]