class ZipTricks::FileReader::InflatingReader

Rubocop: convention: Missing top-level class documentation comment.

Public Class Methods

new(from_io, compressed_data_size) click to toggle source
# File lib/zip_tricks/file_reader/inflating_reader.rb, line 5
def initialize(from_io, compressed_data_size)
  @io = from_io
  @compressed_data_size = compressed_data_size
  @already_read = 0
  @zlib_inflater = ::Zlib::Inflate.new(-Zlib::MAX_WBITS)
end

Public Instance Methods

eof?() click to toggle source
# File lib/zip_tricks/file_reader/inflating_reader.rb, line 33
def eof?
  @zlib_inflater.finished?
end
extract(n_bytes = nil) click to toggle source
# File lib/zip_tricks/file_reader/inflating_reader.rb, line 12
def extract(n_bytes = nil)
  n_bytes ||= (@compressed_data_size - @already_read)

  return if eof?

  available = @compressed_data_size - @already_read

  return if available.zero?

  n_bytes = available if n_bytes > available

  return '' if n_bytes.zero?

  compressed_chunk = @io.read(n_bytes)

  return if compressed_chunk.nil?

  @already_read += compressed_chunk.bytesize
  @zlib_inflater.inflate(compressed_chunk)
end