class Xlsxrb::Ooxml::ZipReader::EntryStreamIO
IO-like stream wrapper that decompresses entry chunks on demand without full buffering.
Constants
- DEFAULT_CHUNK_SIZE
Attributes
compressed_size
[R]
untyped
compression_method
[R]
untyped
data_offset
[R]
untyped
Public Class Methods
(untyped io, Integer data_offset, Integer compressed_size, Integer compression_method, ?max_uncompressed_size: Integer?) → void
Source
# File lib/xlsxrb/ooxml/zip_reader.rb, line 41 def initialize(io, data_offset, compressed_size, compression_method, max_uncompressed_size: nil) @io = io @data_offset = data_offset @compressed_size = compressed_size @compression_method = compression_method @max_uncompressed_size = max_uncompressed_size || ZipReader::MAX_UNCOMPRESSED_SIZE @buffer = +"" @bytes_read_compressed = 0 @total_uncompressed = 0 @eof = false @closed = false @bom_checked = false @inflater = @compression_method == 8 ? Zlib::Inflate.new(-Zlib::MAX_WBITS) : nil end
Public Instance Methods
() → void
Source
# File lib/xlsxrb/ooxml/zip_reader.rb, line 98 def close return if @closed @closed = true begin @inflater&.reset rescue StandardError nil end @inflater&.close @inflater = nil @buffer.clear nil end
(?Integer chunk_size) ?{ (String) → void } → (void | Enumerator[String, void])
Source
# File lib/xlsxrb/ooxml/zip_reader.rb, line 86 def each_chunk(chunk_size = DEFAULT_CHUNK_SIZE, &block) return enum_for(:each_chunk, chunk_size) unless block raise IOError, "closed stream" if @closed while (chunk = read(chunk_size)) break if chunk.nil? || chunk.empty? yield chunk end end
() → bool
Source
# File lib/xlsxrb/ooxml/zip_reader.rb, line 119 def eof? @eof && @buffer.empty? end
(?Integer? length) → String?
Source
# File lib/xlsxrb/ooxml/zip_reader.rb, line 57 def read(length = nil) raise IOError, "closed stream" if @closed check_bom_encoding! if length.nil? result = @buffer.dup @buffer.clear while (chunk = fetch_chunk(DEFAULT_CHUNK_SIZE)) result << chunk end return result end return "" if length.zero? while @buffer.bytesize < length && !@eof chunk = fetch_chunk([length - @buffer.bytesize, DEFAULT_CHUNK_SIZE].max) break unless chunk @buffer << chunk end return nil if @buffer.empty? && @eof @buffer.slice!(0, length) end