[LZMA] Add LZMAProperties initializer which reads lzma encoded properties from bytereader

This commit is contained in:
Timofey Solomko
2018-08-28 11:36:34 +03:00
parent 9a79aa8e51
commit f5d8d9e81e
3 changed files with 8 additions and 5 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ public class LZMA: DecompressionAlgorithm {
*/
public static func decompress(data: Data) throws -> Data {
let byteReader = ByteReader(data: data)
let properties = try LZMAProperties(lzmaByte: byteReader.byte(), byteReader.int(fromBytes: 4))
let properties = try LZMAProperties(byteReader)
let uncompSize = byteReader.int(fromBytes: 8)
return try decompress(byteReader, properties, uncompSize)
}
+6
View File
@@ -3,6 +3,8 @@
//
// See LICENSE for license information
import BitByteData
public struct LZMAProperties {
public var lc: Int
@@ -43,4 +45,8 @@ public struct LZMAProperties {
self.dictionarySize = dictSize
}
init(_ byteReader: ByteReader) throws {
try self.init(lzmaByte: byteReader.byte(), byteReader.int(fromBytes: 4))
}
}
+1 -4
View File
@@ -89,10 +89,7 @@ public class ZipContainer: Container {
case .lzma:
#if (!SWCOMPRESSION_POD_ZIP) || (SWCOMPRESSION_POD_ZIP && SWCOMPRESSION_POD_LZMA)
byteReader.offset += 4 // Skipping LZMA SDK version and size of properties.
fileData = try LZMA.decompress(byteReader,
LZMAProperties(lzmaByte: byteReader.byte(),
byteReader.int(fromBytes: 4)),
uncompSize.toInt())
fileData = try LZMA.decompress(byteReader, LZMAProperties(byteReader), uncompSize.toInt())
#else
throw ZipError.compressionNotSupported
#endif