class Zip::Entry
- Zip::Entry
- Reference
- Object
Overview
File entry in Archive.
Use Zip.read() to read a Zip archive, then #[] to fetch a
specific archive entry.
Example:
# create MemoryIO
io = MemoryIO.new
# open "foo.zip"
Zip.read("foo.zip") do |zip|
# get "bar.txt" entry from "foo.zip"
e = zip["bar.txt"]
# read contents of "bar.txt" into io
e.read(io)
end
Included Modules
Defined in:
Class Method Summary
-
.new(io : Source)
Instantiate a new
Entryobject from the given IO.
Instance Method Summary
-
#comment : String
Get comment for this
Entryas aString. -
#compressed_size : UInt32
Get compressed size for this
Entryas aUInt32. -
#crc : UInt32
Get CRC-32 for this
Entryas aUInt32. -
#dir? : Bool
Returns true if this entry a directory.
-
#external : UInt32
Get external attributes for this
Entryas aUInt32. - #extras : Array(Zip::Extra)
-
#flags : UInt16
Get
GeneralFlagsfor thisEntry. -
#internal : UInt16
Get internal attributes for this
Entryas aUInt16. - #local_extras : Array(Extra)
-
#method : Zip::CompressionMethod
Get
CompressionMethodfor thisEntry. -
#path : String
Get path for this
Entryas aString. -
#pos : UInt32
Get position for this
Entryas aUInt32. -
#size : UInt32
Get uncompressed size for this
Entryas aUInt32. -
#time : Time
Get
Timefor thisEntry. - #version : UInt16
- #version_needed : UInt16
-
#write(path : String) : UInt32
Write contents of
Entryinto given path path and return the number of bytes written. -
#write(dst_io : IO) : UInt32
Write contents of
Entryinto givenIO.
Class Method Detail
Instantiate a new Entry object from the given IO.
You should not need to call this method directly (use
Zip::Archive#[] instead).
Instance Method Detail
Get comment for this Entry as a String.
Zip.read("foo.zip") do |zip|
# print comment for each entry
zip.each do |e|
puts "#{e.path} comment: #{e.comment}"
end
endGet compressed size for this Entry as a UInt32.
Zip.read("foo.zip") do |zip|
# print compressed size for each entry
zip.each do |e|
puts "#{e.path} compressed size: #{e.compressed_size}"
end
endGet CRC-32 for this Entry as a UInt32.
Zip.read("foo.zip") do |zip|
# print crc for each entry
zip.each do |e|
puts "#{e.path} CRC-32: #{e.crc}"
end
endReturns true if this entry a directory.
Example:
Zip.read("foo.zip") do |zip|
type = zip["some-dir/"].dir? ? "directory" : "file"
puts "#{path} is a #{type}"
endGet external attributes for this Entry as a UInt32.
Zip.read("foo.zip") do |zip|
# print external attributes for each entry
zip.each do |e|
puts "#{e.path} external attributes: #{e.external}"
end
endGet Extra data for this Entry as an Array.
Zip.read("foo.zip") do |zip|
# print number of extra data items for each entry
zip.each do |e|
puts "#{e.path} extras: #{e.extras.size}"
end
endGet GeneralFlags for this Entry.
Zip.read("foo.zip") do |zip|
# print flags for each entry
zip.each do |e|
puts "#{e.path} flags: #{e.flags}"
end
endGet internal attributes for this Entry as a UInt16.
Zip.read("foo.zip") do |zip|
# print internal attributes for each entry
zip.each do |e|
puts "#{e.path} internal attributes: #{e.internal}"
end
endReturns an array of Extra attributes for this Entry.
Zip archives can (and do) have separate Extra attributes
associated with the file entry itself, and the file's entry in the
Central Directory.
The #extras method returns the Extra attributes from the
file's entry in the Central Directory, and this method returns the
Extra data from the file entry itself.
Example:
# open "./foo.zip"
Zip.read("./foo.zip") do |zip|
# get array of local extra attributes from "bar.txt"
extras = zip["bar.txt"].local_extras
endGet CompressionMethod for this Entry.
Zip.read("foo.zip") do |zip|
# print compression method for each entry
zip.each do |e|
puts "#{e.path} compression method: #{e.method}"
end
endGet path for this Entry as a String.
Zip.read("foo.zip") do |zip|
# print uncompressed size for each entry
zip.each do |e|
puts "#{e.path}"
end
endGet position for this Entry as a UInt32.
Zip.read("foo.zip") do |zip|
# print position for each entry
zip.each do |e|
puts "#{e.path} position: #{e.pos}"
end
endGet uncompressed size for this Entry as a UInt32.
Zip.read("foo.zip") do |zip|
# print uncompressed size for each entry
zip.each do |e|
puts "#{e.path} uncompressed size: #{e.size}"
end
endGet Time for this Entry.
Zip.read("foo.zip") do |zip|
# print time for each entry
zip.each do |e|
puts "#{e.path} time: #{e.time}"
end
endGet Version used to generate this Entry.
Zip.read("foo.zip") do |zip|
# print version used for each entry
zip.each do |e|
puts "#{e.path} version used: #{e.version}"
end
endGet Version needed to generate this Entry.
Zip.read("foo.zip") do |zip|
# print version needed to extract each entry
zip.each do |e|
puts "#{e.path} version needed: #{e.version_needed}"
end
endWrite contents of Entry into given path path and return the
number of bytes written.
Raises an Error if the file contents could not be read or if the
compression method is unsupported.
Example:
# open "output-bar.txt" for writing
File.open("output-bar.txt", "wb") do |io|
# open archive "./foo.zip"
Zip.read("foo.zip") do |zip|
# write contents of "bar.txt" to "output-bar.txt"
zip["foo.txt"].write(io)
end
endWrite contents of Entry into given IO.
Raises an Error if the file contents could not be read or if the
compression method is unsupported.
Example:
# open "output-bar.txt" for writing
File.open("output-bar.txt", "wb") do |io|
# open archive "./foo.zip"
Zip.read("foo.zip") do |zip|
# write contents of "bar.txt" to "output-bar.txt"
zip["foo.txt"].write(io)
end
end