Class: Digest::Base
- Inherits:
-
Object
- Object
- Digest::Base
- Defined in:
- lib/rook/helper/digest.rb
Class Method Summary collapse
-
.create_from_file(filename) ⇒ Object
create digest object from file content.
-
.file_digest(filename) ⇒ Object
return digest value of file content.
-
.file_hexdigest(filename) ⇒ Object
return hex-digest value of file content.
Class Method Details
.create_from_file(filename) ⇒ Object
create digest object from file content
ex.
require 'digest/md5'
digest = Digest::MD5.create_from_file('largefile.mov')
puts digest.hexdigest
this is faster than ‘Digest::MD5.new(File.read(“largefile.mov”))’ when file size is large.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rook/helper/digest.rb', line 26 def self.create_from_file(filename) digest = self.new File.open(filename) do |f| #size = 4 * 1024 # 4KB #size = 8 * 1024 # 8KB size = 16 * 1024 # 16KB #size = 32 * 1024 # 32KB #size = 64 * 1024 # 64KB #size = 128 * 1024 # 128KB #size = 256 * 1024 # 256KB #size = 512 * 1024 # 512KB #size = 1 * 1024 * 1024 # 1MB #size = 4 * 1024 * 1024 # 4MB buf = '' digest.update(buf) while f.read(size, buf) end return digest end |
.file_digest(filename) ⇒ Object
return digest value of file content
ex.
require 'digest/md5'
puts Digest::MD5.digest('largefile.mov')
this is faster than ‘Digest::MD5.digest(File.read(filename))’ when file size is large.
71 72 73 |
# File 'lib/rook/helper/digest.rb', line 71 def self.file_digest(filename) return self.create_from_file(filename).digest end |
.file_hexdigest(filename) ⇒ Object
return hex-digest value of file content
ex.
require 'digest/md5'
puts Digest::MD5.hex_digest('largefile.mov')
this is faster than ‘Digest::MD5.hex_digest(File.read(filename))’ when file size is large.
56 57 58 |
# File 'lib/rook/helper/digest.rb', line 56 def self.file_hexdigest(filename) return self.create_from_file(filename).hexdigest end |