Class: Mongo::Grid::File::Chunk
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/mongo/grid/file/chunk.rb |
Overview
Encapsulates behavior around GridFS chunks of file data.
Constant Summary
-
COLLECTION =
Name of the chunks collection.
'chunks'.freeze
-
DEFAULT_SIZE =
Default size for chunks of data.
(255 * 1024).freeze
Class Method Summary
-
.assemble(chunks) ⇒ String
Internal use only
Internal use only
Takes an array of chunks and assembles them back into the full piece of raw data.
-
.new(document) ⇒ Chunk
constructor
Create the new chunk.
-
.split(io, file_info, offset = 0) ⇒ Array<Chunk>
Internal use only
Internal use only
Split the provided data into multiple chunks.
Instance Attribute Summary
- #document ⇒ BSON::Document readonly
Instance Method Summary
-
#==(other) ⇒ true, false
Check chunk equality.
-
#bson_type ⇒ Integer
Get the BSON type for a chunk document.
-
#data ⇒ BSON::Binary
Get the chunk data.
-
#files_id ⇒ BSON::ObjectId
Get the files id.
-
#id ⇒ BSON::ObjectId
Get the chunk id.
-
#n ⇒ Integer
Get the chunk position.
-
#to_bson(buffer = BSON::ByteBuffer.new, validating_keys = nil) ⇒ String
Conver the chunk to BSON for storage.
Constructor Details
.new(document) ⇒ Chunk
Create the new chunk.
Class Method Details
.assemble(chunks) ⇒ String
Takes an array of chunks and assembles them back into the full piece of raw data.
.split(io, file_info, offset = 0) ⇒ Array
<Chunk
>
Split the provided data into multiple chunks.
# File 'lib/mongo/grid/file/chunk.rb', line 176
def split(io, file_info, offset = 0) io = StringIO.new(io) if io.is_a?(String) parts = Enumerator.new { |y| y << io.read(file_info.chunk_size) until io.eof? } parts.map.with_index do |bytes, n| file_info.update_md5(bytes) Chunk.new( data: BSON::Binary.new(bytes), files_id: file_info.id, n: n + offset ) end end
Instance Attribute Details
#document ⇒ BSON::Document
(readonly)
# File 'lib/mongo/grid/file/chunk.rb', line 39
attr_reader :document
Instance Method Details
#==(other) ⇒ true
, false
Check chunk equality.
#bson_type ⇒ Integer
Get the BSON type for a chunk document.
# File 'lib/mongo/grid/file/chunk.rb', line 64
def bson_type BSON::Hash::BSON_TYPE end
#data ⇒ BSON::Binary
Get the chunk data.
# File 'lib/mongo/grid/file/chunk.rb', line 76
def data document[:data] end
#files_id ⇒ BSON::ObjectId
Get the files id.
# File 'lib/mongo/grid/file/chunk.rb', line 100
def files_id document[:files_id] end
#id ⇒ BSON::ObjectId
Get the chunk id.
# File 'lib/mongo/grid/file/chunk.rb', line 88
def id document[:_id] end
#n ⇒ Integer
Get the chunk position.
# File 'lib/mongo/grid/file/chunk.rb', line 112
def n document[:n] end
#to_bson(buffer = BSON::ByteBuffer.new, validating_keys = nil) ⇒ String
Conver the chunk to BSON for storage.