Class: Mongo::Grid::File Deprecated

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
build/ruby-driver-v2.19/lib/mongo/grid/file.rb,
build/ruby-driver-v2.19/lib/mongo/grid/file/info.rb,
build/ruby-driver-v2.19/lib/mongo/grid/file/chunk.rb

Overview

Deprecated.

Please use the ‘stream’ API on a FSBucket instead. Will be removed in driver version 3.0.

A representation of a file in the database.

Since:

  • 2.0.0

Defined Under Namespace

Classes: Chunk, Info

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, options = {}) ⇒ File

Initialize the file.

Examples:

Create the file.

Grid::File.new(data, :filename => 'test.txt')

Parameters:

  • data (IO, String, Array<BSON::Document>)

    The file object, file contents or chunks.

  • options (BSON::Document, Hash) (defaults to: {})

    The info options.

  • opts (Hash)

    a customizable set of options

Options Hash (options):

  • :filename (String)

    Required name of the file.

  • :content_type (String)

    The content type of the file. Deprecated, please use the metadata document instead.

  • :metadata (String)

    Optional file metadata.

  • :chunk_size (Integer)

    Override the default chunk size.

Since:

  • 2.0.0



76
77
78
79
80
# File 'build/ruby-driver-v2.19/lib/mongo/grid/file.rb', line 76

def initialize(data, options = {})
  options = options.merge(:length => data.size) unless options[:length]
  @info = Info.new(options)
  initialize_chunks!(data)
end

Instance Attribute Details

#chunksArray<Chunk> (readonly)

Returns chunks The file chunks.

Returns:

  • (Array<Chunk>)

    chunks The file chunks.

Since:

  • 2.0.0



37
38
39
# File 'build/ruby-driver-v2.19/lib/mongo/grid/file.rb', line 37

def chunks
  @chunks
end

#infoFile::Info (readonly)

Returns info The file information.

Returns:

Since:

  • 2.0.0



40
41
42
# File 'build/ruby-driver-v2.19/lib/mongo/grid/file.rb', line 40

def info
  @info
end

Instance Method Details

#==(other) ⇒ true, false

Check equality of files.

Examples:

Check the equality of files.

file == other

Parameters:

  • other (Object)

    The object to check against.

Returns:

  • (true, false)

    If the objects are equal.

Since:

  • 2.0.0



52
53
54
55
# File 'build/ruby-driver-v2.19/lib/mongo/grid/file.rb', line 52

def ==(other)
  return false unless other.is_a?(File)
  chunks == other.chunks && info == other.info
end

#dataString

Joins chunks into a string.

Returns:

  • (String)

    The raw data for the file.

Since:

  • 2.0.0



87
88
89
# File 'build/ruby-driver-v2.19/lib/mongo/grid/file.rb', line 87

def data
  @data ||= Chunk.assemble(chunks)
end

#inspectString

Gets a pretty inspection of the file.

Examples:

Get the file inspection.

file.inspect

Returns:

  • (String)

    The file inspection.

Since:

  • 2.0.0



99
100
101
# File 'build/ruby-driver-v2.19/lib/mongo/grid/file.rb', line 99

def inspect
  "#<Mongo::Grid::File:0x#{object_id} filename=#{filename}>"
end