Class: Mongo::Grid::File::Info Deprecated
- Inherits:
-
Object
- Object
- Mongo::Grid::File::Info
- Defined in:
- lib/mongo/grid/file/info.rb
Overview
Please use the ‘stream’ API on a FSBucket instead. Will be removed in driver version 3.0.
Encapsulates behaviour around GridFS files collection file document.
Constant Summary collapse
- COLLECTION =
Name of the files collection.
'files'.freeze
- MAPPINGS =
Mappings of user supplied fields to db specification.
{ :chunk_size => :chunkSize, :content_type => :contentType, :filename => :filename, :_id => :_id, :md5 => :md5, :length => :length, :metadata => :metadata, :upload_date => :uploadDate, :aliases => :aliases }.freeze
- DEFAULT_CONTENT_TYPE =
Default content type for stored files.
'binary/octet-stream'.freeze
Instance Attribute Summary collapse
-
#document ⇒ BSON::Document
readonly
Document The files collection document.
Instance Method Summary collapse
-
#==(other) ⇒ true, false
Is this file information document equal to another?.
-
#bson_type ⇒ Integer
Get the BSON type for a files information document.
-
#chunk_size ⇒ Integer
Get the file chunk size.
-
#content_type ⇒ String
Get the file information content type.
-
#filename ⇒ String
Get the filename from the file information.
-
#id ⇒ BSON::ObjectId
Get the file id from the file information.
-
#initialize(document) ⇒ Info
constructor
Create the new file information document.
-
#inspect ⇒ String
Get a readable inspection for the object.
-
#length ⇒ Integer
(also: #size)
Get the length of the document in bytes.
-
#md5 ⇒ String
Get the md5 hash.
-
#metadata ⇒ String
Get the additional metadata from the file information document.
-
#to_bson(buffer = BSON::ByteBuffer.new, validating_keys = BSON::Config.validating_keys?) ⇒ String
Convert the file information document to BSON for storage.
-
#upload_date ⇒ Time
Get the upload date.
Constructor Details
Instance Attribute Details
#document ⇒ BSON::Document (readonly)
Returns document The files collection document.
53 54 55 |
# File 'lib/mongo/grid/file/info.rb', line 53 def document @document end |
Instance Method Details
#==(other) ⇒ true, false
Is this file information document equal to another?
65 66 67 68 |
# File 'lib/mongo/grid/file/info.rb', line 65 def ==(other) return false unless other.is_a?(Info) document == other.document end |
#bson_type ⇒ Integer
Get the BSON type for a files information document.
78 79 80 |
# File 'lib/mongo/grid/file/info.rb', line 78 def bson_type BSON::Hash::BSON_TYPE end |
#chunk_size ⇒ Integer
Get the file chunk size.
90 91 92 |
# File 'lib/mongo/grid/file/info.rb', line 90 def chunk_size document[:chunkSize] end |
#content_type ⇒ String
Get the file information content type.
102 103 104 |
# File 'lib/mongo/grid/file/info.rb', line 102 def content_type document[:contentType] end |
#filename ⇒ String
Get the filename from the file information.
112 113 114 |
# File 'lib/mongo/grid/file/info.rb', line 112 def filename document[:filename] end |
#id ⇒ BSON::ObjectId
Get the file id from the file information.
124 125 126 |
# File 'lib/mongo/grid/file/info.rb', line 124 def id document[:_id] end |
#inspect ⇒ String
Get a readable inspection for the object.
149 150 151 152 |
# File 'lib/mongo/grid/file/info.rb', line 149 def inspect "#<Mongo::Grid::File::Info:0x#{object_id} chunk_size=#{chunk_size} " + "filename=#{filename} content_type=#{content_type} id=#{id} md5=#{md5}>" end |
#length ⇒ Integer Also known as: size
Get the length of the document in bytes.
162 163 164 |
# File 'lib/mongo/grid/file/info.rb', line 162 def length document[:length] end |
#md5 ⇒ String
Get the md5 hash.
187 188 189 |
# File 'lib/mongo/grid/file/info.rb', line 187 def md5 document[:md5] || @client_md5 end |
#metadata ⇒ String
Get the additional metadata from the file information document.
175 176 177 |
# File 'lib/mongo/grid/file/info.rb', line 175 def document[:metadata] end |
#to_bson(buffer = BSON::ByteBuffer.new, validating_keys = BSON::Config.validating_keys?) ⇒ String
If no md5 exists in the file information document (it was loaded from the server and is not a new file) then we digest the md5 and set it.
Convert the file information document to BSON for storage.
205 206 207 208 |
# File 'lib/mongo/grid/file/info.rb', line 205 def to_bson(buffer = BSON::ByteBuffer.new, validating_keys = BSON::Config.validating_keys?) document[:md5] ||= @client_md5.hexdigest document.to_bson(buffer) end |
#upload_date ⇒ Time
Get the upload date.
218 219 220 |
# File 'lib/mongo/grid/file/info.rb', line 218 def upload_date document[:uploadDate] end |