Class: Rmega::Nodes::File
- Includes:
- Deletable
- Defined in:
- lib/rmega/nodes/file.rb
Instance Attribute Summary
Attributes inherited from Node
Instance Method Summary collapse
Methods included from Deletable
Methods inherited from Node
#attributes, #can_decrypt_attributes?, #decrypted_file_key, #file_key, #handle, #initialize, #name, #owner_key, #parent_handle, #public_handle, #public_url, #public_url=, #type
Methods included from Traversable
#children, #empty?, #files, #folders, #parent
Methods included from Loggable
Constructor Details
This class inherits a constructor from Rmega::Nodes::Node
Instance Method Details
#download(path) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rmega/nodes/file.rb', line 18 def download(path) path = ::File.(path) path = Dir.exists?(path) ? ::File.join(path, name) : path logger.info "Download #{name} (#{size} 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: size, 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 path end |
#size ⇒ Object
14 15 16 |
# File 'lib/rmega/nodes/file.rb', line 14 def size data['s'] end |
#storage_url ⇒ Object
10 11 12 |
# File 'lib/rmega/nodes/file.rb', line 10 def storage_url @storage_url ||= data['g'] || request(a: 'g', g: 1, n: handle)['g'] end |