Class: Aliyun::Oss::Utils
- Inherits:
-
Object
- Object
- Aliyun::Oss::Utils
- Defined in:
- lib/aliyun/oss/utils.rb
Class Method Summary collapse
-
.content_size(content) ⇒ Integer
Calculate content length.
- .hash_slice(hash, *selected_keys) ⇒ Hash
-
.md5_digest(body) ⇒ String
Digest body with MD5 and then encoding with Base64.
-
.to_data(file_or_bin) ⇒ Bin data
Convert File or Bin data to bin data.
-
.to_xml(hash) ⇒ Object
nodoc.
Class Method Details
.content_size(content) ⇒ Integer
Calculate content length
12 13 14 15 16 17 18 |
# File 'lib/aliyun/oss/utils.rb', line 12 def self.content_size(content) if content.respond_to?(:size) content.size elsif content.is_a?(IO) content.stat.size end end |
.hash_slice(hash, *selected_keys) ⇒ Hash
31 32 33 34 35 |
# File 'lib/aliyun/oss/utils.rb', line 31 def self.hash_slice(hash, *selected_keys) new_hash = {} selected_keys.each { |k| new_hash[k] = hash[k] if hash.key?(k) } new_hash end |
.md5_digest(body) ⇒ String
Digest body with MD5 and then encoding with Base64
23 24 25 |
# File 'lib/aliyun/oss/utils.rb', line 23 def self.md5_digest(body) Base64.encode64(Digest::MD5.digest(body)).strip end |
.to_data(file_or_bin) ⇒ Bin data
Convert File or Bin data to bin data
40 41 42 |
# File 'lib/aliyun/oss/utils.rb', line 40 def self.to_data(file_or_bin) file_or_bin.respond_to?(:read) ? IO.binread(file_or_bin) : file end |
.to_xml(hash) ⇒ Object
nodoc
44 45 46 |
# File 'lib/aliyun/oss/utils.rb', line 44 def self.to_xml(hash) # nodoc %(<?xml version="1.0" encoding="UTF-8"?>#{Gyoku.xml(hash)}) end |