Class: Tus::Checksum
- Inherits:
-
Object
- Object
- Tus::Checksum
- Defined in:
- lib/tus/checksum.rb
Overview
Generates various checksums for given IO objects. The following algorithms are supported:
-
SHA1
-
SHA256
-
SHA384
-
SHA512
-
MD5
-
CRC32
Constant Summary collapse
- CHUNK_SIZE =
16*1024
Instance Attribute Summary collapse
-
#algorithm ⇒ Object
readonly
Returns the value of attribute algorithm.
Class Method Summary collapse
Instance Method Summary collapse
- #generate(io) ⇒ Object
-
#initialize(algorithm) ⇒ Checksum
constructor
A new instance of Checksum.
- #match?(checksum, io) ⇒ Boolean
Constructor Details
#initialize(algorithm) ⇒ Checksum
Returns a new instance of Checksum.
22 23 24 |
# File 'lib/tus/checksum.rb', line 22 def initialize(algorithm) @algorithm = algorithm end |
Instance Attribute Details
#algorithm ⇒ Object (readonly)
Returns the value of attribute algorithm.
16 17 18 |
# File 'lib/tus/checksum.rb', line 16 def algorithm @algorithm end |
Class Method Details
.generate(algorithm, input) ⇒ Object
18 19 20 |
# File 'lib/tus/checksum.rb', line 18 def self.generate(algorithm, input) new(algorithm).generate(input) end |
Instance Method Details
#generate(io) ⇒ Object
30 31 32 33 34 |
# File 'lib/tus/checksum.rb', line 30 def generate(io) hash = send("generate_#{algorithm}", io) io.rewind hash end |
#match?(checksum, io) ⇒ Boolean
26 27 28 |
# File 'lib/tus/checksum.rb', line 26 def match?(checksum, io) generate(io) == checksum end |