class Xlsxrb::Ooxml::ZipReader
Reads ZIP archives using only stdlib (zlib). Scans local file headers sequentially — works with non-seekable IO.
Constants
- LOCAL_HEADER_SIG
Public Class Methods
Source
# File lib/xlsxrb/ooxml/zip_reader.rb, line 28 def initialize(io) @io = io @entries = nil end
# File lib/xlsxrb/ooxml/zip_reader.rb, line 14 def self.open(source) io = source.is_a?(String) ? File.open(source, "rb") : source reader = new(io) if block_given? begin yield reader ensure io.close if source.is_a?(String) end else reader end end
Opens a ZIP from a file path or IO and yields the reader.
Public Instance Methods
Source
# File lib/xlsxrb/ooxml/zip_reader.rb, line 46 def each_entry(&block) return enum_for(:each_entry) unless block entries.each_pair(&block) end
Yields (entry_name, data_string) for each file in the archive.
Source
# File lib/xlsxrb/ooxml/zip_reader.rb, line 34 def read_all result = {} each_entry { |name, data| result[name] = data } result end
Returns a Hash { entry_name => raw_bytes } for all entries.
Source
# File lib/xlsxrb/ooxml/zip_reader.rb, line 41 def read_entry(name) entries[name] end
Returns raw bytes for a single entry, or nil if not found.