[LZMA] Replace LZMAProperties.updateProperties with init from lzma byte and dict size

This commit is contained in:
Timofey Solomko
2018-08-28 11:21:33 +03:00
parent 8737e6e2df
commit 4e6d3beea9
3 changed files with 6 additions and 9 deletions
+1 -2
View File
@@ -171,12 +171,11 @@ class SevenZipFolder {
properties.count == 5
else { throw LZMAError.wrongProperties }
var lzmaProperties = try LZMAProperties(lzmaByte: properties[0])
var dictionarySize = 0
for i in 1..<4 {
dictionarySize |= properties[i].toInt() << (8 * (i - 1))
}
lzmaProperties.dictionarySize = dictionarySize
let lzmaProperties = try LZMAProperties(lzmaByte: properties[0], dictionarySize)
decodedData = try LZMA.decompress(data: decodedData,
properties: lzmaProperties,
uncompressedSize: unpackSize)
+3 -6
View File
@@ -30,12 +30,7 @@ public struct LZMAProperties {
self.dictionarySize = 0
}
init(lzmaByte: UInt8) throws {
self.init()
try self.updateProperties(lzmaByte: lzmaByte)
}
mutating func updateProperties(lzmaByte: UInt8) throws {
init(lzmaByte: UInt8, _ dictSize: Int) throws {
guard lzmaByte < 9 * 5 * 5
else { throw LZMAError.wrongProperties }
@@ -44,6 +39,8 @@ public struct LZMAProperties {
self.lc = intByte % 9
self.pb = (intByte / 9) / 5
self.lp = (intByte / 9) % 5
self.dictionarySize = dictSize
}
}
+2 -1
View File
@@ -99,7 +99,8 @@ final class LZMA2Decoder {
scheme and resets decoder's state and sub-decoders.
*/
private func updateProperties() throws {
try self.decoder.properties.updateProperties(lzmaByte: byteReader.byte())
self.decoder.properties = try LZMAProperties(lzmaByte: byteReader.byte(),
self.decoder.properties.dictionarySize)
self.decoder.resetStateAndDecoders()
}