Module: Digest::Instance

Defined in:
lib/gorge/digest/instance.rb

Instance Method Summary collapse

Instance Method Details

#io(io_like) ⇒ self

Updates the Digest using the entire contents of the given IO-like, and returns the Digest modified. Seeks to the beginning of the IO-like before reading, and restores its initial position after reading. See also Digest::Instance#file.

Parameters:

  • io_like (IO, StringIO, IO-like)

Returns:

  • (self)


10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/gorge/digest/instance.rb', line 10

def io(io_like)
  pos = io_like.pos # save position
  io_like.seek(0)

  buffer = ""
  while io_like.read(16384, buffer)
    self.update(buffer)
  end

  io_like.seek(pos) # restore position

  self
end