Class: Foxify::ResumableSHA1
- Inherits:
-
Object
- Object
- Foxify::ResumableSHA1
- Defined in:
- lib/foxify/resumable_sha1.rb
Overview
A resumable SHA1 implementation
Constant Summary collapse
- CHUNK_SIZE =
1024 * 1024 * 5
Instance Attribute Summary collapse
-
#finalized ⇒ Object
readonly
Returns the value of attribute finalized.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #hexdigest ⇒ Object
-
#initialize(state = nil, finalized: false) ⇒ ResumableSHA1
constructor
A new instance of ResumableSHA1.
- #reset ⇒ Object
- #to_msgpack ⇒ Object
- #update(data) ⇒ Object (also: #<<)
Constructor Details
#initialize(state = nil, finalized: false) ⇒ ResumableSHA1
Returns a new instance of ResumableSHA1.
12 13 14 15 16 |
# File 'lib/foxify/resumable_sha1.rb', line 12 def initialize(state = nil, finalized: false) @state = state @finalized = finalized reset unless @state end |
Instance Attribute Details
#finalized ⇒ Object (readonly)
Returns the value of attribute finalized.
10 11 12 |
# File 'lib/foxify/resumable_sha1.rb', line 10 def finalized @finalized end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
10 11 12 |
# File 'lib/foxify/resumable_sha1.rb', line 10 def state @state end |
Class Method Details
.file(path) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/foxify/resumable_sha1.rb', line 45 def self.file(path) new.tap do |t| stream = File.open(path, "rb") t.update stream.read(CHUNK_SIZE) until stream.eof? stream.close end end |
.from_msgpack(data) ⇒ Object
61 62 63 64 |
# File 'lib/foxify/resumable_sha1.rb', line 61 def self.from_msgpack(data) state, finalized = MessagePack.unpack(data) new(state, finalized:) end |
.hexdigest(data) ⇒ Object
41 42 43 |
# File 'lib/foxify/resumable_sha1.rb', line 41 def self.hexdigest(data) new.update(data).hexdigest end |
Instance Method Details
#==(other) ⇒ Object
53 54 55 |
# File 'lib/foxify/resumable_sha1.rb', line 53 def ==(other) self.class == other.class && state == other.state && finalized == other.finalized end |
#hexdigest ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/foxify/resumable_sha1.rb', line 33 def hexdigest raise Foxify::Error, "Invalid state - this is already finalized" if @finalized Foxify::Native.sha1_finalize(@state).tap do @finalized = true end end |
#reset ⇒ Object
18 19 20 21 22 |
# File 'lib/foxify/resumable_sha1.rb', line 18 def reset @state = Foxify::Native.sha1_init @finalized = false self end |
#to_msgpack ⇒ Object
57 58 59 |
# File 'lib/foxify/resumable_sha1.rb', line 57 def to_msgpack [@state, @finalized].to_msgpack end |