class Thingfish::Processor::SHA256
Calculate and store a sha256 checksum for a resource.
Constants
- CHUNK_SIZE
The chunk size to read
Public Instance Methods
on_request( request )
click to toggle source
Synchronous processor API – generate a checksum during upload.
# File lib/thingfish/processor/sha256.rb, line 24 def on_request( request ) request.add_metadata( :checksum => self.checksum(request.body) ) request.related_resources.each_pair do |io, metadata| metadata[ :checksum ] = self.checksum( io ) end end
Protected Instance Methods
checksum( io )
click to toggle source
Given an io
, return a sha256 checksum of it's contents.
# File lib/thingfish/processor/sha256.rb, line 37 def checksum( io ) digest = Digest::SHA256.new buf = String.new while io.read( CHUNK_SIZE, buf ) digest.update( buf ) end io.rewind return digest.hexdigest end