class LibZip::File

A zip archive, open for reading, writing, or both.

An archive is a transaction: entries added, removed and renamed are noted as you go, and close writes them to disk. The block form of ::open commits on normal exit and throws the archive away if the block fails, so a failed write can’t leave a truncated zip behind.

LibZip::File.open("archive.zip", create: true) do |zip|
  zip.add("a.txt", "a.txt")
  zip.get_output_stream("b.txt") { |out| out.write("from memory") }
end

LibZip::File.open("archive.zip") do |zip|
  zip.names                 # => ["a.txt", "b.txt"]
  zip.read("b.txt")         # => "from memory"
end

File includes Enumerable over its LibZip::Entry records, so map, select and the rest work on a listing.

Once the archive is closed, all of these fail with LibZip::EntryError.