ZipContainer

public class ZipContainer

Provides function to open ZIP archives (containers).

  • All file and directory entries found in ZIP archive (in its Central Directory).

    Declaration

    Swift

    public private(set) var entries: [ZipEntry]
  • Tries to open ZIP archive and parse its Central Directory. If parsing is successful then entries property will contain all directory or file entries found in archive.

    Important

    The order of entries is defined by ZIP archive and, particularly, creator of given ZIP container. It is likely that directories will be encountered earlier than files stored in those directories, but one SHOULD NOT assume that this is the case.

    Note

    Currently, there is no universal (platform and file system independent) method to determine if entry is a directory. One can check this by looking at the size of entry’s data (it should be 0 for directory) AND the last character of entry’s name (it should be ‘/’). If all of these is true then entry is likely to be a directory.

    Note

    Only ZIP containers complying to ISO/IEC 21320-1 standard are supported.

    Throws

    ZipError or DeflateError depending on the type of inconsistency in data. It may indicate that either the container is damaged or it might not be ZIP container or compressed with Deflate at all.

    Declaration

    Swift

    public init(containerData data: Data) throws

    Parameters

    containerData

    Data of ZIP container.

  • Returns data associated with provided ZipEntry.

    Note

    Returned Data object with the size of 0 can either indicate that the entry is an empty file or it is a directory.

    Throws

    ZipError or DeflateError depending on the type of inconsistency in data. An error can indicate that the container is damaged.

    Declaration

    Swift

    public func data(for zipEntry: ZipEntry) throws -> Data

    Parameters

    zipEntry

    file or directory entry from current container.

  • Processes ZIP archive (container) and returns an array of tuples (String, Data). First member of a tuple is entry’s name, second member is entry’s data.

    Important

    The order of entries is defined by ZIP archive and, particularly, creator of given ZIP container. It is likely that directories will be encountered earlier than files stored in those directories, but one SHOULD NOT assume that this is the case.

    Note

    Currently, there is no universal (platform and file system independent) method to determine if entry is a directory. One can check this by looking at the size of entry’s data (it should be 0 for directory) AND the last character of entry’s name (it should be ‘/’). If all of these is true then entry is likely to be a directory.

    Note

    Only ZIP containers complying to ISO/IEC 21320-1 standard are supported.

    Throws

    ZipError or DeflateError depending on the type of inconsistency in data. It may indicate that either the container is damaged or it might not be ZIP container or compressed with Deflate at all.

    Declaration

    Swift

    public static func open(containerData data: Data) throws -> [(entryName: String, entryData: Data)]

    Parameters

    containerData

    Data of ZIP container.

    Return Value

    Array of pairs (tuples) where first member is entryName and second member is entryData.