class AWS::Glacier::ArchiveCollection

def [] archive_id

Returns:
  • (Archive) -

Parameters:
  • archive_id (String) --
def [] archive_id
  Archive.new(vault, archive_id, :config => config, :account_id => account_id)
end

def compute_checksums data

but that requires reading the data a 2nd time. :(
The sigv4 module will compute the hash of the payload for us,

(via sigv4).
the simple hash is required for generating the signature
The tree hash is required by the streaming operations,

* a tree hash of the entire payload
* a hash of the entire payload
Computes two checksums in a single pass of the data:
def compute_checksums data
  digest = OpenSSL::Digest::Digest.new('sha256')
  tree_digest = OpenSSL::Digest::Digest.new('sha256')
  tree_parts = []
  until data.eof?
    chunk = data.read(1024 * 1024) # read 1MB
    tree_parts << tree_digest.update(chunk).digest
    tree_digest.reset
    digest.update(chunk)
  end
  data.rewind
  [digest.to_s, compute_tree_hash(tree_parts)]
end

def compute_tree_hash hashes

def compute_tree_hash hashes
  digest = OpenSSL::Digest::Digest.new('sha256')
  until hashes.count == 1
    hashes = hashes.each_slice(2).map do |h1,h2|
      digest.reset
      if h2
        digest.update(h1)
        digest.update(h2)
        digest.digest
      else
        h1
      end
    end
  end
  hashes.first.bytes.map{|x| x.to_i.to_s(16).rjust(2,'0')}.join('')
end

def convert_to_io data

def convert_to_io data
  return Core::ManagedFile.open(data) if
    data.is_a?(Pathname) or data.is_a?(String)
  return data if io_like?(data)
  msg = "expected data to be IO-like or a file path (String/Pathanme)."
  raise ArgumentError, msg
end

def create data, options = {}

Returns:
  • (Archive) -

Options Hash: (**options)
  • description (String) --

Parameters:
  • options (Hash) --
  • data (File, Pathname, IO, String) -- The data to upload.
def create data, options = {}
  data = convert_to_io(data)
  hash, tree_hash = compute_checksums(data)
  upload_options = {}
  upload_options[:vault_name] = vault.name
  upload_options[:account_id] = account_id
  upload_options[:body] = data
  upload_options[:checksum] = tree_hash
  upload_options[:content_sha256] = hash
  upload_options[:archive_description] = options[:description] if
    options[:description]
  resp = client.upload_archive(upload_options)
  self[resp[:archive_id]]
end

def initialize vault, options = {}

Options Hash: (**options)
  • :account_id (String) --

Parameters:
  • options (Hash) --
  • vault (Vault) --
def initialize vault, options = {}
  @vault = vault
  @account_id = options[:account_id] || '-'
  super
end

def io_like? data

Returns:
  • (Boolean) - Returns `tue` if data acts like a file.
def io_like? data
  data.respond_to?(:read) and
  data.respond_to?(:eof?) and
  data.respond_to?(:rewind) and
  data.respond_to?(:size)
end