class LibZip::InputStream
A read handle on 1 entry, from LibZip::File#get_input_stream.
The entry is decompressed and decrypted in chunks as you read, so memory remains flat whatever the entry’s size.
LibZip::File.open("archive.zip") do |zip| zip.get_input_stream("big.csv") do |stream| stream.read(64 * 1024) until stream.eof? end end
A stream keeps a libzip handle and has to be closed. The block form of LibZip::File#get_input_stream does that for you; otherwise close does, and LibZip::File#close closes whatever is still open on that archive.
Public Instance Methods
Source
# File doc/api.rb, line 461 def close end
Releases the entry handle. Returns nil, and has no effect on a stream that’s already closed.
Source
# File doc/api.rb, line 456 def closed? end
Whether the stream has been closed, by close or by closing the archive.
Source
# File doc/api.rb, line 452 def eof? end
Whether the entry has been read to the end. Fails with LibZip::EntryError once the stream is closed.
Source
# File doc/api.rb, line 447 def read(length = nil) end
Returns length bytes, or the rest of the entry when length is omitted.
Returns an ASCII-8BIT String. A short read means the entry ended: fewer than length bytes come back, and the call after that gives nil. With no length, a stream already at EOF gives "", the same distinction IO makes. read(0) gives "" and consumes no bytes, even at EOF.
Fails with ArgumentError for a negative length, LibZip::EntryError once the stream is closed, and LibZip::DecompressionError when the data doesn’t match its CRC or its AES HMAC, which is only known once the entry has been read to the end.