Method: PEROBS::BTreeBlob#write_object

Defined in:
lib/perobs/BTreeBlob.rb

#write_object(id, raw) ⇒ Object

Write the given bytes with the given ID into the DB.

Parameters:

  • id (Fixnum or Bignum)

    ID

  • raw (String)

    sequence of bytes



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/perobs/BTreeBlob.rb', line 70

def write_object(id, raw)
  if @entries.length > @btreedb.max_blob_size
    # The blob has reached the maximum size. Replace the blob with a BTree
    # node directory and distribute the blob entires into the sub-blobs of
    # the new BTree node.
    split_blob
    # Insert the passed object into the newly created BTree node.
    @btreedb.put_raw_object(raw, id)
  else
    bytes = raw.bytesize
    crc32 = Zlib.crc32(raw, 0)
    start_address = reserve_bytes(id, bytes, crc32)
    if write_to_blobs_file(raw, start_address) != bytes
      PEROBS.log.fatal 'Object length does not match written bytes'
    end
    write_index
  end
end