Class: Mongo::Grid::File Deprecated

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/mongo/grid/file.rb,
lib/mongo/grid/file/info.rb,
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



73
74
75
76
77
# File 'lib/mongo/grid/file.rb', line 73

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



34
35
36
# File 'lib/mongo/grid/file.rb', line 34

def chunks
  @chunks
end

#infoFile::Info (readonly)

Returns info The file information.

Returns:

Since:

  • 2.0.0



37
38
39
# File 'lib/mongo/grid/file.rb', line 37

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



49
50
51
52
# File 'lib/mongo/grid/file.rb', line 49

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



84
85
86
# File 'lib/mongo/grid/file.rb', line 84

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



96
97
98
# File 'lib/mongo/grid/file.rb', line 96

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