GzipArchive

public class GzipArchive: Archive

Provides unarchive and archive functions for GZip archives.

  • Represents a member of multi-member of GZip archive.

    See more

    Declaration

    Swift

    public struct Member
  • Unarchives GZip archive.

    If data passed is not actually a GZip archive, GzipError will be thrown.

    If data in archive is not actually compressed with Deflate algorithm, DeflateError will be thrown.

    Note

    This function is specification compliant.

    Throws

    DeflateError or GzipError depending on the type of the problem. It may indicate that either archive is damaged or it might not be archived with GZip or compressed with Deflate at all.

    Declaration

    Swift

    public static func unarchive(archive data: Data) throws -> Data

    Parameters

    archive

    Data archived with GZip.

    Return Value

    Unarchived data.

  • Unarchives multi-member GZip archive. Multi-member GZip archives are essentially several GZip archives following each other in a single file.

    Note

    wrongCRC error contains only last processed member’s data as their associated value instead of all successfully processed members. This is a known issue and it will be fixed in future major version because solution requires backwards-incompatible API changes.

    Throws

    DeflateError or GzipError depending on the type of the problem. It may indicate that one of the members of archive is damaged or it might not be archived with GZip or compressed with Deflate at all.

    Declaration

    Swift

    public static func multiUnarchive(archive data: Data) throws -> [Member]

    Parameters

    archive

    GZip archive with one or more members.

    Return Value

    Unarchived data.

  • Archives data into GZip archive, using various specified options. Data will be also compressed with Deflate algorithm. It will be also specified in archive’s header that the compressor used the slowest Deflate algorithm.

    If during compression something goes wrong DeflateError will be thrown. If either fileName or comment cannot be encoded with ISO Latin-1 encoding, then GzipError.cannotEncodeISOLatin1 will be thrown.

    Note

    This function is specification compliant.

    Throws

    DeflateError or GzipError.cannotEncodeISOLatin1 depending on the type of of the problem.

    Declaration

    Swift

    public static func archive(data: Data, comment: String? = nil, fileName: String? = nil,
                                   writeHeaderCRC: Bool = false, isTextFile: Bool = false,
                                   osType: GzipHeader.FileSystemType? = nil, modificationTime: Date? = nil) throws -> Data

    Parameters

    data

    Data to compress and archive.

    comment

    Additional comment, which will be stored as a separate field in archive.

    fileName

    Name of the file which will be archived.

    writeHeaderCRC

    Set to true, if you want to store consistency check for archive’s header.

    isTextFile

    Set to true, if the file which will be archived is text file or ASCII-file.

    osType

    Type of the system on which this archive will be created.

    modificationTime

    Last time the file was modified.

    Return Value

    Resulting archive’s data.