Sha256: b22047cc1cc4aeb3581024e3faa87d44e28b3ea471dd65e2d83692f487e01078

Contents?: true

Size: 805 Bytes

Versions: 1

Compression:

Stored size: 805 Bytes

Contents

require_relative '../downloader'

module Rmega
  class FileNode < Node
    def storage_url
      @storage_url ||= data['g'] || request(a: 'g', g: 1, n: handle)['g']
    end

    def download(path)
      path = File.expand_path(path)
      path = Dir.exists?(path) ? File.join(path, name) : path

      logger.info "Download #{name} (#{filesize} bytes) => #{path}"

      k = decrypted_file_key
      k = [k[0] ^ k[4], k[1] ^ k[5], k[2] ^ k[6], k[3] ^ k[7]]
      nonce = decrypted_file_key[4..5]

      donwloader = Downloader.new(base_url: storage_url, filesize: filesize, local_path: path)

      donwloader.download do |start, buffer|
        nonce = [nonce[0], nonce[1], (start/0x1000000000) >> 0, (start/0x10) >> 0]
        Crypto::AesCtr.decrypt(k, nonce, buffer)[:data]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rmega-0.0.6 lib/rmega/nodes/file_node.rb