LZ4

public enum LZ4 : DecompressionAlgorithm
extension LZ4: CompressionAlgorithm

Provides functions for compression and decompression for LZ4 algorithm.

  • Decompresses data using LZ4 algortihm.

    Use LZ4.decompress(data:dictionary:dictionaryID:) instead, if the data was compressed with an external dictionary. Otherwise, the decompression will result in an error or incorrect output.

    Throws

    DataError.corrupted or DataError.truncated if the data is corrupted or truncated. DataError.checksumMismatch is thrown with uncompressed data as its associated value if the computed checksum of the uncompressed data does not match the stored checksum. DataError.unsupportedFeature is thrown when the value of a field inside the frame, such as uncompressed data size, is incompatible with the maximum integer size of the current platform.

    Declaration

    Swift

    public static func decompress(data: Data) throws -> Data

    Parameters

    data

    Data compressed with LZ4. If data represents several concatenated LZ4 frames, only the first frame will be processed; use LZ4.multiDecompress(data:dictionary:dictionaryID:) instead to decompress all the frames.

  • Decompresses data using LZ4 algortihm and provided external dictionary.

    Throws

    DataError.corrupted or DataError.truncated if the data is corrupted or truncated. DataError.checksumMismatch is thrown with uncompressed data as its associated value if the computed checksum of the uncompressed data does not match the stored checksum. DataError.unsupportedFeature is thrown when the value of a field inside the frame, such as uncompressed data size, is incompatible with the maximum integer size of the current platform.

    Declaration

    Swift

    public static func decompress(data: Data, dictionary: Data?, dictionaryID: UInt32? = nil) throws -> Data

    Parameters

    data

    Data compressed with LZ4. If data represents several concatenated LZ4 frames, only the first frame will be processed; use LZ4.multiDecompress(data:dictionary:dictionaryID:) instead to decompress all the frames.

    dictionary

    External dictionary which will be used during decompression. Providing incorrect dictionary (not the one that was used for compression), no dictionary at all (if one was used for compression), or providing a dictionary when no dictionary was used for compression will result in an error or incorrect output.

    dictionaryID

    Optional dictionary ID, which must match the one stored in the frame. If no dictionary ID is present in the frame, then this argument is ignored.

  • Decompresses data, which may represent several concatenated LZ4 frames, using LZ4 algortihm and provided external dictionary.

    Throws

    DataError.corrupted or DataError.truncated if the data is corrupted or truncated. DataError.checksumMismatch is thrown if the computed checksum of the uncompressed data does not match the stored checksum. The associated value in this case contains uncompressed data from all the frames up to and including the one that caused this error. DataError.unsupportedFeature is thrown when the value of a field inside a frame, such as uncompressed data size, is incompatible with the maximum integer size of the current platform.

    Declaration

    Swift

    public static func multiDecompress(data: Data, dictionary: Data? = nil, dictionaryID: UInt32? = nil) throws -> [Data]

    Parameters

    data

    Data compressed with LZ4. If data represents several concatenated LZ4 frames, all of them will be processed.

    dictionary

    External dictionary which will be used during decompression of all encountered frames. Providing incorrect dictionary (not the one that was used for compression), no dictionary at all (if one was used for compression), or providing a dictionary when no dictionary was used for compression will result in an error or incorrect output.

    dictionaryID

    Optional dictionary ID, which must match the one stored in all frames. If no dictionary ID is present in a frame, then this argument is ignored for that frame.

    Return Value

    An array with uncompressed data from each processed non-skippable LZ4 frame as its elements.

  • Compresses data using LZ4 algortihm with default format and algorithm options.

    The default options include: independent blocks, do not save checksums for compressed blocks, save the checksum of the uncompressed data, do not save the size of the uncompressed data, use 4 MB block size, no dictionary.

    Declaration

    Swift

    public static func compress(data: Data) -> Data
  • Compresses data using LZ4 algortihm.

    This function allows to customize format and alogrithm options or use an external dictionary to compress the data.

    Precondition

    blockSize must be greater than zero and less than or equal to 4194304 (4 MB).

    Declaration

    Swift

    public static func compress(data: Data, independentBlocks: Bool, blockChecksums: Bool,
                                 contentChecksum: Bool, contentSize: Bool, blockSize: Int = 4 * 1024 * 1024,
                                 dictionary: Data? = nil, dictionaryID: UInt32? = nil) -> Data

    Parameters

    data

    Data to compress.

    independentBlocks

    True, if compressed blocks should be independent of each other. Setting this to false may improve compression ratio at the cost of decompression speed.

    blockChecksums

    True, if the checksums of the compressed blocks should be stored in the output.

    contentChecksum

    True, if the checksum of the uncompressed data should be stored in the output.

    contentSize

    True, if the size of the uncompressed data should be stored in the output.

    blockSize

    Size of uncompressed blocks in bytes. The default and maximum value is 4194304 (4 MB).

    dictionary

    External dictionary which will be used during compression. The same dictionary then must be used for successful decompression.

    dictionaryID

    Optional dictionary ID which will be stored in the output. The same dictionary ID then is likely to be required for successful decompression.