class Zip::ZipFile
- Zip::ZipFile
- IO
- Reference
- Object
Overview
Thin IO
wrapper for reading files from archives. Use
Archive#open
to get an instance.
Example
# open "foo.txt" in archive
str = zip.open("foo.txt") do |file|
# build result string
String.build |b|
# read file in chunks
file.read do |buf, len|
b.write(buf[0, len])
end
end
end
# print file contents
puts "file contents: #{str}"
Defined in:
zip/file.crInstance Method Summary
-
#close : Nil
Close this
File
instance. -
#error : ErrorCode
Return last archive error as an
ErrorCode
instance. -
#read(slice : Slice(UInt8))
Read bytes into
Slice
slice and return number of bytes read (or -1 on error). -
#system_error : LibC::Int
Return last system error for this file.
-
#write(slice : Slice(UInt8)) : Nil
File
instances are read-only so this method unconditionally throws anException
.
Instance Method Detail
Close this File
instance.
Raises an exception if this File
is not open.
Example
# close file
file.close
Return last archive error as an ErrorCode
instance.
Raises an exception if this File
is not open.
Example
# get and print last error
puts file.error
Read bytes into Slice
slice and return number of bytes read
(or -1 on error).
Raises an exception if this File
is not open.
Example
# create slice buffer
buf = Slice(UInt8).new(10)
# read up to 10 bytes into buf and return number of bytes read
len = file.read(buf)
Return last system error for this file.
Raises an exception if this File
is not open.
Example
# get and print last system error
puts file.system_error
File
instances are read-only so this method unconditionally
throws an Exception
.