LZ4
public enum LZ4 : DecompressionAlgorithm
extension LZ4: CompressionAlgorithm
Provides functions for compression and decompression for LZ4 algorithm.
-
Decompresses
datausing 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.corruptedorDataError.truncatedif the data is corrupted or truncated.DataError.checksumMismatchis thrown with uncompressed data as its associated value if the computed checksum of the uncompressed data does not match the stored checksum.DataError.unsupportedFeatureis 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 -> DataParameters
dataData compressed with LZ4. If
datarepresents several concatenated LZ4 frames, only the first frame will be processed; useLZ4.multiDecompress(data:dictionary:dictionaryID:)instead to decompress all the frames. -
Decompresses
datausing LZ4 algortihm and provided external dictionary.Throws
DataError.corruptedorDataError.truncatedif the data is corrupted or truncated.DataError.checksumMismatchis thrown with uncompressed data as its associated value if the computed checksum of the uncompressed data does not match the stored checksum.DataError.unsupportedFeatureis 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 -> DataParameters
dataData compressed with LZ4. If
datarepresents several concatenated LZ4 frames, only the first frame will be processed; useLZ4.multiDecompress(data:dictionary:dictionaryID:)instead to decompress all the frames.dictionaryExternal 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.
dictionaryIDOptional 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.corruptedorDataError.truncatedif the data is corrupted or truncated.DataError.checksumMismatchis 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.unsupportedFeatureis 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
dataData compressed with LZ4. If
datarepresents several concatenated LZ4 frames, all of them will be processed.dictionaryExternal 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.
dictionaryIDOptional 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
datausing 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 -
compress(data:independentBlocks: blockChecksums: contentChecksum: contentSize: blockSize: dictionary: dictionaryID: ) Compresses
datausing LZ4 algortihm.This function allows to customize format and alogrithm options or use an external dictionary to compress the data.
Precondition
blockSizemust 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) -> DataParameters
dataData to compress.
independentBlocksTrue, if compressed blocks should be independent of each other. Setting this to
falsemay improve compression ratio at the cost of decompression speed.blockChecksumsTrue, if the checksums of the compressed blocks should be stored in the output.
contentChecksumTrue, if the checksum of the uncompressed data should be stored in the output.
contentSizeTrue, if the size of the uncompressed data should be stored in the output.
blockSizeSize of uncompressed blocks in bytes. The default and maximum value is 4194304 (4 MB).
dictionaryExternal dictionary which will be used during compression. The same dictionary then must be used for successful decompression.
dictionaryIDOptional dictionary ID which will be stored in the output. The same dictionary ID then is likely to be required for successful decompression.
View on GitHub
LZ4 Enumeration Reference