Class: Mongo::Grid::File::Info Deprecated
| Relationships & Source Files | |
| Inherits: | Object |
| Defined in: | lib/mongo/grid/file/info.rb |
Overview
Please use the ‘stream’ API on a ::Mongo::Grid::FSBucket instead. Will be removed in driver version 3.0.
Encapsulates behavior around GridFS files collection file document.
Constant Summary
-
COLLECTION =
# File 'lib/mongo/grid/file/info.rb', line 30
Name of the files collection.
'files' -
DEFAULT_CONTENT_TYPE =
# File 'lib/mongo/grid/file/info.rb', line 50
Default content type for stored files.
'binary/octet-stream' -
MAPPINGS =
# File 'lib/mongo/grid/file/info.rb', line 35
Mappings of user supplied fields to db specification.
{ chunk_size: :chunkSize, content_type: :contentType, filename: :filename, _id: :_id, md5: :md5, length: :length, metadata: :, upload_date: :uploadDate, aliases: :aliases }.freeze
Class Method Summary
-
.new(document) ⇒ Info
constructor
Create the new file information document.
Instance Attribute Summary
- #document ⇒ BSON::Document readonly
Instance Method Summary
-
#==(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.
-
#inspect ⇒ String
Get a readable inspection for the object.
-
#length ⇒ Integer
(also: #size)
Get the length of the document in bytes.
-
#md5 ⇒ String
deprecated
Deprecated.
as of 2.6.0
-
#metadata ⇒ String
Get the additional metadata from the file information document.
-
#size
Alias for #length.
-
#to_bson(buffer = BSON::ByteBuffer.new, _validating_keys = nil) ⇒ String
Convert the file information document to BSON for storage.
-
#update_md5(bytes) ⇒ Digest::MD5
deprecated
Deprecated.
as of 2.6.0
-
#upload_date ⇒ Time
Get the upload date.
- #default_document private
Constructor Details
.new(document) ⇒ Info
Create the new file information document.
# File 'lib/mongo/grid/file/info.rb', line 137
def initialize(document) @client_md5 = Digest::MD5.new unless document[:disable_md5] == true # document contains a mix of user options and keys added # internally by the driver, like session. # Remove the keys that driver adds but keep user options. document = document.reject do |key, _value| key.to_s == 'session' end @document = default_document.merge(Options::Mapper.transform(document, MAPPINGS)) end
Instance Attribute Details
#document ⇒ BSON::Document (readonly)
# File 'lib/mongo/grid/file/info.rb', line 53
attr_reader :document
Instance Method Details
#==(other) ⇒ true, false
Is this file information document equal to another?
#bson_type ⇒ Integer
Get the BSON type for a files information document.
# File 'lib/mongo/grid/file/info.rb', line 79
def bson_type BSON::Hash::BSON_TYPE end
#chunk_size ⇒ Integer
Get the file chunk size.
# File 'lib/mongo/grid/file/info.rb', line 91
def chunk_size document[:chunkSize] end
#content_type ⇒ String
Get the file information content type.
# File 'lib/mongo/grid/file/info.rb', line 103
def content_type document[:contentType] end
#default_document (private)
# File 'lib/mongo/grid/file/info.rb', line 253
def default_document BSON::Document.new( _id: BSON::ObjectId.new, chunkSize: Chunk::DEFAULT_SIZE, # MongoDB stores times with millisecond precision uploadDate: Time.now.utc.round(3), contentType: DEFAULT_CONTENT_TYPE ) end
#filename ⇒ String
Get the filename from the file information.
# File 'lib/mongo/grid/file/info.rb', line 113
def filename document[:filename] end
#id ⇒ BSON::ObjectId
Get the file id from the file information.
# File 'lib/mongo/grid/file/info.rb', line 125
def id document[:_id] end
#inspect ⇒ String
Get a readable inspection for the object.
# File 'lib/mongo/grid/file/info.rb', line 156
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.
# File 'lib/mongo/grid/file/info.rb', line 169
def length document[:length] end
#md5 ⇒ String
as of 2.6.0
Get the md5 hash.
# File 'lib/mongo/grid/file/info.rb', line 196
def md5 document[:md5] || @client_md5 end
#metadata ⇒ String
Get the additional metadata from the file information document.
# File 'lib/mongo/grid/file/info.rb', line 182
def document[:] end
#size
Alias for #length.
# File 'lib/mongo/grid/file/info.rb', line 172
alias size length
#to_bson(buffer = BSON::ByteBuffer.new, _validating_keys = nil) ⇒ 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.
#update_md5(bytes) ⇒ Digest::MD5
as of 2.6.0
This method is transitional and is provided for backwards compatibility.
Update the md5 hash if there is one.
It will be removed when md5 support is deprecated entirely.
#upload_date ⇒ Time
Get the upload date.
# File 'lib/mongo/grid/file/info.rb', line 247
def upload_date document[:uploadDate] end