Class: RBzip2::Java::Decompressor
- Inherits:
-
Object
- Object
- RBzip2::Java::Decompressor
- Defined in:
- lib/facter/util/rbzip2-0.3.0/lib/rbzip2/java/decompressor.rb
Overview
This code is free software; you can redistribute it and/or modify it under the terms of the new BSD License.
Copyright © 2013-2017, Sebastian Staudt
Instance Method Summary collapse
- #close ⇒ Object
- #getc ⇒ Object
- #gets ⇒ Object
-
#initialize(io) ⇒ Decompressor
constructor
A new instance of Decompressor.
- #inspect ⇒ Object
- #read(length = nil) ⇒ Object
- #size ⇒ Object
- #uncompressed ⇒ Object
Constructor Details
#initialize(io) ⇒ Decompressor
Returns a new instance of Decompressor.
8 9 10 11 |
# File 'lib/facter/util/rbzip2-0.3.0/lib/rbzip2/java/decompressor.rb', line 8 def initialize(io) @io = io @is = RBzip2::Java::BZip2CompressorInputStream.new io.to_inputstream end |
Instance Method Details
#close ⇒ Object
13 14 15 |
# File 'lib/facter/util/rbzip2-0.3.0/lib/rbzip2/java/decompressor.rb', line 13 def close @is.close end |
#getc ⇒ Object
17 18 19 |
# File 'lib/facter/util/rbzip2-0.3.0/lib/rbzip2/java/decompressor.rb', line 17 def getc read(1)[0].chr end |
#gets ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/facter/util/rbzip2-0.3.0/lib/rbzip2/java/decompressor.rb', line 21 def gets line = '' loop do char = getc line += char break if char == "\n" end line end |
#inspect ⇒ Object
61 62 63 |
# File 'lib/facter/util/rbzip2-0.3.0/lib/rbzip2/java/decompressor.rb', line 61 def inspect "#<#{self.class}: @io=#{@io.inspect} size=#{size} uncompressed=#{uncompressed}>" end |
#read(length = nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/facter/util/rbzip2-0.3.0/lib/rbzip2/java/decompressor.rb', line 31 def read(length = nil) if length.nil? bytes = Java::byte[0].new chunk = Java::byte[1024].new begin bytes_read = @is.read chunk chunk = chunk[0..(bytes_read - 1)] if bytes_read < 1024 bytes += chunk end while bytes_read == 1024 else bytes = Java::byte[length].new @is.read bytes end String.from_java_bytes bytes end |
#size ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/facter/util/rbzip2-0.3.0/lib/rbzip2/java/decompressor.rb', line 48 def size if @io.is_a? StringIO @io.size elsif @io.is_a? File @io.stat.size end end |
#uncompressed ⇒ Object
56 57 58 59 |
# File 'lib/facter/util/rbzip2-0.3.0/lib/rbzip2/java/decompressor.rb', line 56 def uncompressed @data = read @data.size end |