Method: Mongo::Grid::File::Info#to_bson

Defined in:
lib/mongo/grid/file/info.rb

#to_bson(buffer = BSON::ByteBuffer.new, validating_keys = nil) ⇒ String

Note:

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.

Examples:

Convert the file information document to BSON.

file_info.to_bson

Parameters:

  • buffer (BSON::ByteBuffer) (defaults to: BSON::ByteBuffer.new)

    The encoded BSON buffer to append to.

  • validating_keys (true, false) (defaults to: nil)

    Whether keys should be validated when serializing. This option is deprecated and will not be used. It will removed in version 3.0.

Returns:

  • (String)

    The raw BSON data.

Since:

  • 2.0.0



236
237
238
239
240
241
# File 'lib/mongo/grid/file/info.rb', line 236

def to_bson(buffer = BSON::ByteBuffer.new, validating_keys = nil)
  if @client_md5 && !document[:md5]
    document[:md5] = @client_md5.hexdigest
  end
  document.to_bson(buffer)
end