mirror of
https://github.com/tsolomko/SWCompression.git
synced 2026-06-23 14:56:41 +00:00
I've also removed a most occurrences of inout keyword because DWP (and BitReader) are classes and they are already passed by reference in arguments.
42 lines
1.4 KiB
Swift
42 lines
1.4 KiB
Swift
// Copyright (c) 2017 Timofey Solomko
|
|
// Licensed under MIT License
|
|
//
|
|
// See LICENSE for license information
|
|
|
|
import Foundation
|
|
|
|
/// Provides decompression function for LZMA algorithm.
|
|
public class LZMA: DecompressionAlgorithm {
|
|
|
|
/**
|
|
Decompresses `data` using LZMA algortihm.
|
|
|
|
If `data` is not actually compressed with LZMA, `LZMAError` will be thrown.
|
|
|
|
- Parameter data: Data compressed with LZMA.
|
|
|
|
- Throws: `LZMAError` if unexpected byte (bit) sequence was encountered in `data`.
|
|
It may indicate that either data is damaged or it might not be compressed with LZMA at all.
|
|
|
|
- Returns: Decompressed data.
|
|
*/
|
|
public static func decompress(data: Data) throws -> Data {
|
|
/// Object with input data which supports convenient work with bit shifts.
|
|
let pointerData = DataWithPointer(data: data)
|
|
|
|
return Data(bytes: try decompress(pointerData))
|
|
}
|
|
|
|
/**
|
|
- Parameter externalUncompressedSize: stream doesn't contain uncompressed size property,
|
|
and decoder should use externally specified uncompressed size.
|
|
Used in ZIP containers with LZMA compression.
|
|
*/
|
|
static func decompress(_ pointerData: DataWithPointer, _ externalUncompressedSize: Int? = nil) throws -> [UInt8] {
|
|
let lzmaDecoder = try LZMADecoder(pointerData)
|
|
try lzmaDecoder.decodeLZMA(externalUncompressedSize)
|
|
return lzmaDecoder.out
|
|
}
|
|
|
|
}
|