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
Entry
object from the given IO.
Instance Method Summary
-
#comment : String
Get comment for this
Entry
as aString
. -
#compressed_size : UInt64
Get compressed size for this
Entry
. -
#crc : UInt32
Get CRC-32 for this
Entry
as aUInt32
. -
#dir? : Bool
Returns true if this entry a directory.
-
#external : UInt32
Get external attributes for this
Entry
as aUInt32
. - #extras : Array(Zip::Extra::Base)
-
#flags : UInt16
Get
GeneralFlags
for thisEntry
. -
#internal : UInt16
Get internal attributes for this
Entry
as aUInt16
. - #local_extras : Array(Extra::Base)
-
#method : Zip::CompressionMethod
Get
CompressionMethod
for thisEntry
. -
#path : String
Get path for this
Entry
as aString
. -
#pos : UInt64
Get position for this
Entry
. -
#size : UInt64
Get uncompressed size for this
Entry
. -
#time : Time
Get
Time
for thisEntry
. - #version : UInt16
- #version_needed : UInt16
-
#write(path : String) : UInt64
Write contents of
Entry
into given path path and return the number of bytes written. -
#write(dst_io : IO) : UInt64
Write contents of
Entry
into 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
end
Get compressed size for this Entry
.
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
end
Get 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
end
Returns 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}"
end
Get 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
end
Get 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
end
Get 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
end
Get 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
end
Returns 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
end
Get 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
end
Get 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
end
Get position for this Entry
.
Zip.read("foo.zip") do |zip|
# print position for each entry
zip.each do |e|
puts "#{e.path} position: #{e.pos}"
end
end
Get uncompressed size for this Entry
.
Zip.read("foo.zip") do |zip|
# print uncompressed size for each entry
zip.each do |e|
puts "#{e.path} uncompressed size: #{e.size}"
end
end
Get 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
end
Get 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
end
Get 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
end
Write 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
end
Write 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