1. Gem::
  2. Package::
  3. DigestIO

class Gem::Package::DigestIO

IO wrapper that creates digests of contents written to theIO it wraps.

Attributes

digests[R]

Collected digests for wrapped writes.

{  'SHA1'   => #<OpenSSL::Digest: [...]>,  'SHA512' => #<OpenSSL::Digest: [...]>,}

Public Class Methods

Source
# File lib/rubygems/package/digest_io.rb, line 46definitialize(io,digests)@io =io@digests =digestsend

Creates a newDigestIO instance. Using::wrap is recommended, see the::wrap documentation for documentation ofio anddigests.

Source
# File lib/rubygems/package/digest_io.rb, line 34defself.wrap(io,digests)digest_io =newio,digestsyielddigest_iodigestsend

Wrapsio and updates digest for each of the digest algorithms in thedigestsHash. Returns the digests hash. Example:

io =StringIO.newdigests = {'SHA1'=>OpenSSL::Digest.new('SHA1'),'SHA512'=>OpenSSL::Digest.new('SHA512'),}Gem::Package::DigestIO.wrapio,digestsdo|digest_io|digest_io.write"hello"enddigests['SHA1'].hexdigest#=> "aaf4c61d[...]"digests['SHA512'].hexdigest#=> "9b71d224[...]"

Public Instance Methods

Source
# File lib/rubygems/package/digest_io.rb, line 54defwrite(data)result =@io.writedata@digests.eachdo|_,digest|digest<<dataendresultend

Writesdata to the underlyingIO and updates the digests