Sha256: bf2ce8dfa345fbc50bb2af37cf66b2a1764da9b24ef858100feec123b9343e56

Contents?: true

Size: 698 Bytes

Versions: 12

Compression:

Stored size: 698 Bytes

Contents

require 'stringio'

module BerkeleyLibrary
  module Util
    module StringIOs
      class << self
        include StringIOs
      end

      # Returns the byte (**not** character) at the specified byte index
      # in the specified `StringIO`.
      #
      # @param s [StringIO] the StringIO to search in
      # @param i [Integer] the byte index
      # @return [Integer, nil] the byte, or nil if the byte index is invalid.
      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
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
berkeley_library-util-0.1.9 lib/berkeley_library/util/stringios.rb
berkeley_library-util-0.1.8 lib/berkeley_library/util/stringios.rb
berkeley_library-util-0.1.7 lib/berkeley_library/util/stringios.rb
berkeley_library-util-0.1.6 lib/berkeley_library/util/stringios.rb
berkeley_library-util-0.1.5 lib/berkeley_library/util/stringios.rb
berkeley_library-util-0.1.4 lib/berkeley_library/util/stringios.rb
berkeley_library-util-0.1.3 lib/berkeley_library/util/stringios.rb
berkeley_library-util-0.1.2 lib/berkeley_library/util/stringios.rb
berkeley_library-util-0.1.1 lib/berkeley_library/util/stringios.rb
berkeley_library-util-0.1.0 lib/berkeley_library/util/stringios.rb
berkeley_library-tind-0.4.1 lib/berkeley_library/util/stringios.rb
berkeley_library-tind-0.4.0 lib/berkeley_library/util/stringios.rb