Module: BerkeleyLibrary::Util::StringIOs

Extended by:
StringIOs
Included in:
Paths, StringIOs
Defined in:
lib/berkeley_library/util/stringios.rb

Instance Method Summary collapse

Instance Method Details

#getbyte(s, i) ⇒ Integer?

Returns the byte (not character) at the specified byte index in the specified StringIO.

Parameters:

  • s (StringIO)

    the StringIO to search in

  • i (Integer)

    the byte index

Returns:

  • (Integer, nil)

    the byte, or nil if the byte index is invalid.



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/berkeley_library/util/stringios.rb', line 16

def getbyte(s, i)
  return if i >= s.size
  return if s.size + i < 0

  pos_orig = s.pos
  begin
    s.seek(i >= 0 ? i : s.size + i)
    s.getbyte
  ensure
    s.seek(pos_orig)
  end
end