mirror of
https://github.com/tsolomko/SWCompression.git
synced 2026-06-23 14:56:41 +00:00
[LZMA] Replace LZMAProperties.updateProperties with init from lzma byte and dict size
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user