Sha256: d591b69b5b9e4834d78f7f8ed469e2e1308e3ce06e7ddc3c893a11a858934058

Contents?: true

Size: 1.05 KB

Versions: 11

Compression:

Stored size: 1.05 KB

Contents

module GitObjectBrowser

  module Models

    class Bindata

      def initialize(input)
        @in = input
      end

      def switch_source(input)
        tmp = @in
        @in = input
        yield
      ensure
        @in = tmp
      end

      def raw(bytes)
        @in.read(bytes)
      end

      def bytes(bytes)
        @in.read(bytes).unpack('C*')
      end

      def byte
        bytes(1).first
      end

      def int
        @in.read(4).unpack('N').first.to_i
      end

      def hex(bytes)
        @in.read(bytes).unpack('H*').first
      end

      def binstr(bytes)
        @in.read(bytes).unpack('B*').first
      end

      def find_char(char)
        buf = ''
        loop do
          c = @in.read(1)
          return buf if c.nil? || c == char
          buf += c
        end
      end

      def skip(bytes)
        @in.seek(bytes, IO::SEEK_CUR)
      end

      def seek(bytes)
        @in.seek(bytes)
      end

      def peek(bytes)
        result = raw(bytes)
        @in.seek(bytes * -1, IO::SEEK_CUR)
        result
      end

    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
git-object-browser-0.1.3 lib/git-object-browser/models/bindata.rb
git-object-browser-0.1.2 lib/git-object-browser/models/bindata.rb
git-object-browser-0.1.1 lib/git-object-browser/models/bindata.rb
git-object-browser-0.1.0 lib/git-object-browser/models/bindata.rb
git-object-browser-0.0.9 lib/git-object-browser/models/bindata.rb
git-object-browser-0.0.8 lib/git-object-browser/models/bindata.rb
git-object-browser-0.0.7 lib/git-object-browser/models/bindata.rb
git-object-browser-0.0.6 lib/git-object-browser/models/bindata.rb
git-object-browser-0.0.4 lib/git-object-browser/models/bindata.rb
git-object-browser-0.0.3 lib/git-object-browser/models/bindata.rb
git-object-browser-0.0.2 lib/git-object-browser/models/bindata.rb