Sha256: 2bf853de0ab7e7c426f52b5607c63cb0668cfc2aa2455e67289c7401ec5ca9bb

Contents?: true

Size: 674 Bytes

Versions: 7

Compression:

Stored size: 674 Bytes

Contents

class ZipTricks::FileReader::StoredReader
  def initialize(from_io, compressed_data_size)
    @io = from_io
    @compressed_data_size = compressed_data_size
    @already_read = 0
  end

  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
    compressed_chunk
  end

  def eof?
    @already_read >= @compressed_data_size
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
zip_tricks-4.4.2 lib/zip_tricks/file_reader/stored_reader.rb
zip_tricks-4.4.1 lib/zip_tricks/file_reader/stored_reader.rb
zip_tricks-4.4.0 lib/zip_tricks/file_reader/stored_reader.rb
zip_tricks-4.3.0 lib/zip_tricks/file_reader/stored_reader.rb
zip_tricks-4.2.4 lib/zip_tricks/file_reader/stored_reader.rb
zip_tricks-4.2.3 lib/zip_tricks/file_reader/stored_reader.rb
zip_tricks-4.2.2 lib/zip_tricks/file_reader/stored_reader.rb