Class: Valkyrie::StorageAdapter::File
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- Valkyrie::StorageAdapter::File
- Defined in:
- lib/valkyrie/storage_adapter.rb
Direct Known Subclasses
Instance Method Summary collapse
- #checksum(digests:) ⇒ Array<Digest>
- #disk_path ⇒ Object
- #stream ⇒ Object
- #valid?(size: nil, digests:) ⇒ Boolean
Instance Method Details
#checksum(digests:) ⇒ Array<Digest>
89 90 91 92 93 94 95 96 |
# File 'lib/valkyrie/storage_adapter.rb', line 89 def checksum(digests:) io.rewind while (chunk = io.read(4096)) digests.each { |digest| digest.update(chunk) } end digests.map(&:to_s) end |
#disk_path ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/valkyrie/storage_adapter.rb', line 78 def disk_path path = Pathname.new(io.path) if block_given? yield path else path end end |
#stream ⇒ Object
74 75 76 |
# File 'lib/valkyrie/storage_adapter.rb', line 74 def stream io end |
#valid?(size: nil, digests:) ⇒ Boolean
101 102 103 104 105 106 107 |
# File 'lib/valkyrie/storage_adapter.rb', line 101 def valid?(size: nil, digests:) return false if size && io.size.to_i != size.to_i calc_digests = checksum(digests: digests.keys.map { |alg| Digest(alg.upcase).new }) return false unless digests.values == calc_digests true end |