class Zip::ZipFile

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.cr

Instance Method Summary

Instance Method Detail

def close : Nil #

Close this File instance.

Raises an exception if this File is not open.

Example

# close file
file.close

[View source]
def error : ErrorCode #

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

[View source]
def read(slice : Slice(UInt8)) #

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)

[View source]
def system_error : LibC::Int #

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

[View source]
def write(slice : Slice(UInt8)) : Nil #

File instances are read-only so this method unconditionally throws an Exception.


[View source]