From 328345cbe3eaeb5222bf9fcf7ade8a1442d22d5f Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Sun, 29 Oct 2017 12:50:48 +0300 Subject: [PATCH] Add out variable to LZMA2 decoder and change dictionarySize setup --- Sources/LZMA/LZMA2Decoder.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Sources/LZMA/LZMA2Decoder.swift b/Sources/LZMA/LZMA2Decoder.swift index afe1a199..6a9632eb 100644 --- a/Sources/LZMA/LZMA2Decoder.swift +++ b/Sources/LZMA/LZMA2Decoder.swift @@ -10,13 +10,16 @@ class LZMA2Decoder { private let pointerData: DataWithPointer private let decoder: LZMATempDecoder + var out: [UInt8] { + return self.decoder.out + } + init(_ pointerData: DataWithPointer) throws { self.pointerData = pointerData self.decoder = try LZMATempDecoder(pointerData) - self.decoder.dictionarySize = try LZMA2Decoder.calculateDictionarySize(self.pointerData.byte()) } - private static func calculateDictionarySize(_ byte: UInt8) throws -> Int { + func setDictionarySize(_ byte: UInt8) throws { let bits = byte & 0x3F guard byte & 0xC0 == 0 else { throw LZMA2Error.wrongProperties } @@ -30,7 +33,8 @@ class LZMA2Decoder { dictSize = UInt32(2 | (bits.toInt() & 1)) dictSize <<= UInt32(bits.toInt() / 2 + 11) } - return Int(dictSize) + + self.decoder.dictionarySize = Int(dictSize) } /// Main LZMA2 decoder function.