diff --git a/.jazzy.yaml b/.jazzy.yaml
index 2b1d81c0..2a57f2b1 100644
--- a/.jazzy.yaml
+++ b/.jazzy.yaml
@@ -3,11 +3,11 @@ sourcekitten_sourcefile: docs.json
clean: true
author: Timofey Solomko
module: SWCompression
-module_version: 4.5.8
+module_version: 4.5.9
copyright: '© 2021 Timofey Solomko'
readme: README.md
github_url: https://github.com/tsolomko/SWCompression
-github_file_prefix: https://github.com/tsolomko/SWCompression/tree/4.5.8
+github_file_prefix: https://github.com/tsolomko/SWCompression/tree/4.5.9
theme: fullwidth
custom_categories:
diff --git a/.travis.yml b/.travis.yml
index 37a70118..b614ba0c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -10,6 +10,8 @@ jobs:
osx_image: xcode10.3 # Swift 5.0
env:
- HOMEBREW_NO_INSTALL_CLEANUP=1
+ - WATCHOS_ACTIONS='clean build'
+ - WATCHOS_SIMULATOR='Apple Watch Series 4 - 44mm'
before_install:
- brew update
install:
@@ -24,6 +26,8 @@ jobs:
osx_image: xcode11.3 # Swift 5.1
env:
- HOMEBREW_NO_INSTALL_CLEANUP=1
+ - WATCHOS_ACTIONS='clean build'
+ - WATCHOS_SIMULATOR='Apple Watch Series 4 - 44mm'
before_install:
- brew update
install:
@@ -38,6 +42,8 @@ jobs:
osx_image: xcode11.4 # Swift 5.2
env:
- HOMEBREW_NO_INSTALL_CLEANUP=1
+ - WATCHOS_ACTIONS='clean build'
+ - WATCHOS_SIMULATOR='Apple Watch Series 4 - 44mm'
before_install:
- brew update
install:
@@ -52,6 +58,24 @@ jobs:
osx_image: xcode12.4 # Swift 5.3.2
env:
- HOMEBREW_NO_INSTALL_CLEANUP=1
+ - WATCHOS_ACTIONS='clean build'
+ - WATCHOS_SIMULATOR='Apple Watch Series 6 - 44mm'
+ before_install:
+ - brew update
+ install:
+ - ./utils.py ci install-macos
+ before_script:
+ - ./utils.py prepare-workspace macos --xcf
+ script:
+ - ./utils.py ci script-macos
+ - stage: test
+ language: swift
+ os: osx
+ osx_image: xcode12.5 # Swift 5.4
+ env:
+ - HOMEBREW_NO_INSTALL_CLEANUP=1
+ - WATCHOS_ACTIONS='clean test'
+ - WATCHOS_SIMULATOR='Apple Watch Series 6 - 44mm'
before_install:
- brew update
install:
@@ -93,11 +117,21 @@ jobs:
- stage: test
language: generic
os: linux
- dist: focal
+ dist: bionic
env:
- SWIFT_VERSION=5.3.3
install:
- - eval "$(curl -sL https://swiftenv.fuller.li/install.sh)"
+ - ./utils.py ci install-linux
+ script:
+ - ./utils.py ci script-linux
+ - stage: test
+ language: generic
+ os: linux
+ dist: bionic
+ env:
+ - SWIFT_VERSION=5.4
+ install:
+ - ./utils.py ci install-linux
script:
- ./utils.py ci script-linux
- stage: deploy
@@ -122,7 +156,6 @@ jobs:
- ./utils.py ci before-deploy
deploy:
- provider: pages
- skip_cleanup: true
github_token: $GITHUB_TOKEN
local_dir: docs
skip_cleanup: true
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e4767c8b..989429ba 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,10 @@
# Changelog
+## 4.5.9
+
+- Improved performance of LZMA/LZMA2 and, consequently, of XZ.
+- Fixed a rare crash when processing a BZip2 archive which uses non-standard (but allowed) run length values.
+
## 4.5.8
- Fixed incompatibility with Carthage `--use-xcframeworks` method of installation.
diff --git a/SWCompression.podspec b/SWCompression.podspec
index 86c981fc..4f10dc40 100644
--- a/SWCompression.podspec
+++ b/SWCompression.podspec
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = "SWCompression"
- s.version = "4.5.8"
+ s.version = "4.5.9"
s.summary = "A framework with functions for working with compression, archives and containers."
s.description = "A framework with (de)compression algorithms and functions for processing various archives and containers."
diff --git a/SWCompression.xcodeproj/SWCompression.plist b/SWCompression.xcodeproj/SWCompression.plist
index 38b0f04e..ccfd150a 100644
--- a/SWCompression.xcodeproj/SWCompression.plist
+++ b/SWCompression.xcodeproj/SWCompression.plist
@@ -15,10 +15,10 @@
CFBundlePackageType
FMWK
CFBundleShortVersionString
- 4.5.8
+ 4.5.9
CFBundleVersion
- 75
+ 76
NSHumanReadableCopyright
- Copyright © 2021 Timofey Solomko. All rights reserved.
+ Copyright © 2021 Timofey Solomko
diff --git a/SWCompression.xcodeproj/TestSWCompression.plist b/SWCompression.xcodeproj/TestSWCompression.plist
index 00e0c5d4..fbfd44a0 100644
--- a/SWCompression.xcodeproj/TestSWCompression.plist
+++ b/SWCompression.xcodeproj/TestSWCompression.plist
@@ -15,8 +15,8 @@
CFBundlePackageType
BNDL
CFBundleShortVersionString
- 4.5.8
+ 4.5.9
CFBundleVersion
- 75
+ 76
diff --git a/SWCompression.xcodeproj/project.pbxproj b/SWCompression.xcodeproj/project.pbxproj
index 9de63424..0086e555 100644
--- a/SWCompression.xcodeproj/project.pbxproj
+++ b/SWCompression.xcodeproj/project.pbxproj
@@ -213,6 +213,8 @@
06F066771FFB763400312A82 /* test8.bz2 in Resources */ = {isa = PBXBuildFile; fileRef = 06F066111FFB763300312A82 /* test8.bz2 */; };
06F276DF1F2BAB4A00E67335 /* 7zEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06F276DE1F2BAB4900E67335 /* 7zEntry.swift */; };
06FEAD921F54B9CD00AD016E /* EncodingTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06FEAD911F54B9CD00AD016E /* EncodingTree.swift */; };
+ E652D8F3263D670900FC229B /* test_nonstandard_runlength.bz2 in Resources */ = {isa = PBXBuildFile; fileRef = E652D8F2263D670900FC229B /* test_nonstandard_runlength.bz2 */; };
+ E652D8F5263D678000FC229B /* test_nonstandard_runlength.answer in Resources */ = {isa = PBXBuildFile; fileRef = E652D8F4263D678000FC229B /* test_nonstandard_runlength.answer */; };
E66F36242538726E00076A6E /* test_empty.lzma in Resources */ = {isa = PBXBuildFile; fileRef = E66F36232538726E00076A6E /* test_empty.lzma */; };
E66F362C2538E2B700076A6E /* test_empty.zlib in Resources */ = {isa = PBXBuildFile; fileRef = E66F362B2538E2B700076A6E /* test_empty.zlib */; };
/* End PBXBuildFile section */
@@ -435,6 +437,8 @@
06F276DE1F2BAB4900E67335 /* 7zEntry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = 7zEntry.swift; sourceTree = ""; };
06FEAD911F54B9CD00AD016E /* EncodingTree.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = EncodingTree.swift; path = Sources/Common/CodingTree/EncodingTree.swift; sourceTree = SOURCE_ROOT; };
06FED40B1DD7717E0013DFB2 /* BZip2.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BZip2.swift; sourceTree = ""; };
+ E652D8F2263D670900FC229B /* test_nonstandard_runlength.bz2 */ = {isa = PBXFileReference; lastKnownFileType = file; path = test_nonstandard_runlength.bz2; sourceTree = ""; };
+ E652D8F4263D678000FC229B /* test_nonstandard_runlength.answer */ = {isa = PBXFileReference; lastKnownFileType = file; path = test_nonstandard_runlength.answer; sourceTree = ""; };
E66F36232538726E00076A6E /* test_empty.lzma */ = {isa = PBXFileReference; lastKnownFileType = file; path = test_empty.lzma; sourceTree = ""; };
E66F362B2538E2B700076A6E /* test_empty.zlib */ = {isa = PBXFileReference; lastKnownFileType = file; path = test_empty.zlib; sourceTree = ""; };
/* End PBXFileReference section */
@@ -723,6 +727,7 @@
06F065B31FFB763300312A82 /* test7.answer */,
06F065B51FFB763300312A82 /* test8.answer */,
06F065B11FFB763300312A82 /* test9.answer */,
+ E652D8F4263D678000FC229B /* test_nonstandard_runlength.answer */,
);
path = Answers;
sourceTree = "";
@@ -886,6 +891,7 @@
06F0660C1FFB763300312A82 /* test7.bz2 */,
06F066111FFB763300312A82 /* test8.bz2 */,
06F066101FFB763300312A82 /* test9.bz2 */,
+ E652D8F2263D670900FC229B /* test_nonstandard_runlength.bz2 */,
);
path = BZip2;
sourceTree = "";
@@ -934,7 +940,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
- LastUpgradeCheck = 1240;
+ LastUpgradeCheck = 1250;
ORGANIZATIONNAME = "Timofey Solomko";
TargetAttributes = {
06BE1AC71DB410F100EE0F59 = {
@@ -980,6 +986,7 @@
06F066661FFB763400312A82 /* test3.7z in Resources */,
06F0664B1FFB763400312A82 /* test.tar in Resources */,
06F066501FFB763400312A82 /* test_gnu.tar in Resources */,
+ E652D8F5263D678000FC229B /* test_nonstandard_runlength.answer in Resources */,
06F066341FFB763400312A82 /* test1.xz in Resources */,
06F0665F1FFB763400312A82 /* test_multi_blocks.7z in Resources */,
068D070421368617002A6C3B /* test_delta_filter.7z in Resources */,
@@ -1051,6 +1058,7 @@
0698B10F2106344200A7C551 /* test_negative_mtime.tar in Resources */,
06F066561FFB763400312A82 /* SWCompressionSourceCode.tar in Resources */,
069864CA21403CE700755D9B /* test_sha256.xz in Resources */,
+ E652D8F3263D670900FC229B /* test_nonstandard_runlength.bz2 in Resources */,
06F0663D1FFB763400312A82 /* test2.xz in Resources */,
06F066351FFB763400312A82 /* test5.xz in Resources */,
06F066631FFB763400312A82 /* test_complicated_coding_scheme.7z in Resources */,
@@ -1090,7 +1098,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/bash;
- shellScript = "if [[ ${SDK_NAME} == iphone* ]]; then\n if [[ ! -d ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Frameworks/ ]]; then\n mkdir -p ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Frameworks/\n fi\n if [[ -d ${PROJECT_DIR}/Carthage/Build/BitByteData.xcframework/ ]]; then\n if [[ ${SDK_NAME} == iphonesimulator* ]]; then\n cp -a ${PROJECT_DIR}/Carthage/Build/BitByteData.xcframework/ios-*-simulator/BitByteData.framework ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Frameworks/\n else\n cp -a ${PROJECT_DIR}/Carthage/Build/BitByteData.xcframework/ios-arm64_armv7/BitByteData.framework ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Frameworks/\n fi\n else\n cp -a ${PROJECT_DIR}/Carthage/Build/iOS/BitByteData.framework ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Frameworks/\n fi\nelif [[ ${SDK_NAME} == appletv* ]]; then\n if [[ ! -d ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Frameworks/ ]]; then\n mkdir -p ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Frameworks/\n fi\n if [[ -d ${PROJECT_DIR}/Carthage/Build/BitByteData.xcframework/ ]]; then\n if [[ ${SDK_NAME} == appletvsimulator* ]]; then\n cp -a ${PROJECT_DIR}/Carthage/Build/BitByteData.xcframework/tvos-*-simulator/BitByteData.framework ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Frameworks/\n else\n cp -a ${PROJECT_DIR}/Carthage/Build/BitByteData.xcframework/tvos-arm64/BitByteData.framework ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Frameworks/\n fi\n else\n cp -a ${PROJECT_DIR}/Carthage/Build/tvOS/BitByteData.framework ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Frameworks/\n fi\nelif [[ ${SDK_NAME} == watch* ]]; then\n if [[ ! -d ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Frameworks/ ]]; then\n mkdir -p ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Frameworks/\n fi\n if [[ -d ${PROJECT_DIR}/Carthage/Build/BitByteData.xcframework/ ]]; then\n if [[ ${SDK_NAME} == watchossimulator* ]]; then\n cp -a ${PROJECT_DIR}/Carthage/Build/BitByteData.xcframework/watchos-*-simulator/BitByteData.framework ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Frameworks/\n else\n cp -a ${PROJECT_DIR}/Carthage/Build/BitByteData.xcframework/watchos-arm64_32_armv7k/BitByteData.framework ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Frameworks/\n fi\n else\n cp -a ${PROJECT_DIR}/Carthage/Build/watchOS/BitByteData.framework ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Frameworks/\n fi\nelif [[ ${SDK_NAME} == macos* ]]; then\n if [[ ! -d ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Contents/Frameworks/ ]]; then\n mkdir -p ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Contents/Frameworks/\n fi\n if [[ -d ${PROJECT_DIR}/Carthage/Build/BitByteData.xcframework/ ]]; then\n cp -a ${PROJECT_DIR}/Carthage/Build/BitByteData.xcframework/macos-*/BitByteData.framework ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Contents/Frameworks/\n else\n cp -a ${PROJECT_DIR}/Carthage/Build/Mac/BitByteData.framework ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Contents/Frameworks/\n fi\nfi\n\nxattr -rc ${BUILT_PRODUCTS_DIR}\n";
+ shellScript = "if [[ ${SDK_NAME} == iphone* ]]; then\n if [[ ! -d ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Frameworks/ ]]; then\n mkdir -p ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Frameworks/\n fi\n if [[ -d ${PROJECT_DIR}/Carthage/Build/BitByteData.xcframework/ ]]; then\n if [[ ${SDK_NAME} == iphonesimulator* ]]; then\n cp -a ${PROJECT_DIR}/Carthage/Build/BitByteData.xcframework/ios-*-simulator/BitByteData.framework ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Frameworks/\n else\n cp -a ${PROJECT_DIR}/Carthage/Build/BitByteData.xcframework/ios-arm64_armv7/BitByteData.framework ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Frameworks/\n fi\n else\n cp -a ${PROJECT_DIR}/Carthage/Build/iOS/BitByteData.framework ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Frameworks/\n fi\nelif [[ ${SDK_NAME} == appletv* ]]; then\n if [[ ! -d ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Frameworks/ ]]; then\n mkdir -p ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Frameworks/\n fi\n if [[ -d ${PROJECT_DIR}/Carthage/Build/BitByteData.xcframework/ ]]; then\n if [[ ${SDK_NAME} == appletvsimulator* ]]; then\n cp -a ${PROJECT_DIR}/Carthage/Build/BitByteData.xcframework/tvos-*-simulator/BitByteData.framework ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Frameworks/\n else\n cp -a ${PROJECT_DIR}/Carthage/Build/BitByteData.xcframework/tvos-arm64/BitByteData.framework ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Frameworks/\n fi\n else\n cp -a ${PROJECT_DIR}/Carthage/Build/tvOS/BitByteData.framework ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Frameworks/\n fi\nelif [[ ${SDK_NAME} == watch* ]]; then\n if [[ ! -d ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Frameworks/ ]]; then\n mkdir -p ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Frameworks/\n fi\n if [[ -d ${PROJECT_DIR}/Carthage/Build/BitByteData.xcframework/ ]]; then\n if [[ ${SDK_NAME} == watchsimulator* ]]; then\n cp -a ${PROJECT_DIR}/Carthage/Build/BitByteData.xcframework/watchos-*-simulator/BitByteData.framework ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Frameworks/\n else\n cp -a ${PROJECT_DIR}/Carthage/Build/BitByteData.xcframework/watchos-arm64_32_armv7k/BitByteData.framework ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Frameworks/\n fi\n else\n cp -a ${PROJECT_DIR}/Carthage/Build/watchOS/BitByteData.framework ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Frameworks/\n fi\nelif [[ ${SDK_NAME} == macos* ]]; then\n if [[ ! -d ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Contents/Frameworks/ ]]; then\n mkdir -p ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Contents/Frameworks/\n fi\n if [[ -d ${PROJECT_DIR}/Carthage/Build/BitByteData.xcframework/ ]]; then\n cp -a ${PROJECT_DIR}/Carthage/Build/BitByteData.xcframework/macos-*/BitByteData.framework ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Contents/Frameworks/\n else\n cp -a ${PROJECT_DIR}/Carthage/Build/Mac/BitByteData.framework ${BUILT_PRODUCTS_DIR}/TestSWCompression.xctest/Contents/Frameworks/\n fi\nfi\n\nxattr -rc ${BUILT_PRODUCTS_DIR}\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
@@ -1250,7 +1258,7 @@
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
- CURRENT_PROJECT_VERSION = 75;
+ CURRENT_PROJECT_VERSION = 76;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
@@ -1331,7 +1339,7 @@
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
- CURRENT_PROJECT_VERSION = 75;
+ CURRENT_PROJECT_VERSION = 76;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_STRICT_OBJC_MSGSEND = YES;
"FRAMEWORK_SEARCH_PATHS[sdk=appletvos*]" = (
@@ -1377,7 +1385,7 @@
BitByteData,
);
SDKROOT = macosx;
- SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator";
+ SUPPORTED_PLATFORMS = "macosx watchsimulator iphonesimulator appletvsimulator watchos appletvos iphoneos";
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_VERSION = 5.0;
TVOS_DEPLOYMENT_TARGET = 9.0;
@@ -1392,7 +1400,7 @@
APPLICATION_EXTENSION_API_ONLY = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
- DYLIB_CURRENT_VERSION = 75;
+ DYLIB_CURRENT_VERSION = 76;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = SWCompression.xcodeproj/SWCompression.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
@@ -1419,7 +1427,7 @@
APPLICATION_EXTENSION_API_ONLY = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
- DYLIB_CURRENT_VERSION = 75;
+ DYLIB_CURRENT_VERSION = 76;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = SWCompression.xcodeproj/SWCompression.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
diff --git a/SWCompression.xcodeproj/xcshareddata/xcschemes/SWCompression.xcscheme b/SWCompression.xcodeproj/xcshareddata/xcschemes/SWCompression.xcscheme
index 0987e3ca..d423d3f1 100644
--- a/SWCompression.xcodeproj/xcshareddata/xcschemes/SWCompression.xcscheme
+++ b/SWCompression.xcodeproj/xcshareddata/xcschemes/SWCompression.xcscheme
@@ -1,6 +1,6 @@
Int {
return Int(truncatingIfNeeded: self)
}
+
}
extension Int {
diff --git a/Sources/LZMA/LZMA.swift b/Sources/LZMA/LZMA.swift
index d8644301..413b0996 100644
--- a/Sources/LZMA/LZMA.swift
+++ b/Sources/LZMA/LZMA.swift
@@ -63,7 +63,7 @@ public class LZMA: DecompressionAlgorithm {
static func decompress(_ byteReader: LittleEndianByteReader,
_ properties: LZMAProperties,
_ uncompSize: Int?) throws -> Data {
- let decoder = LZMADecoder(byteReader)
+ var decoder = LZMADecoder(byteReader)
decoder.properties = properties
decoder.resetStateAndDecoders()
decoder.uncompressedSize = uncompSize ?? -1
diff --git a/Sources/LZMA/LZMABitTreeDecoder.swift b/Sources/LZMA/LZMABitTreeDecoder.swift
index 8b760e07..577c6373 100644
--- a/Sources/LZMA/LZMABitTreeDecoder.swift
+++ b/Sources/LZMA/LZMABitTreeDecoder.swift
@@ -6,7 +6,7 @@
import Foundation
/// Used to decode symbols that need several bits for storing.
-final class LZMABitTreeDecoder {
+struct LZMABitTreeDecoder {
var probs: [Int]
let numBits: Int
@@ -17,7 +17,7 @@ final class LZMABitTreeDecoder {
self.numBits = numBits
}
- func decode(with rangeDecoder: LZMARangeDecoder) -> Int {
+ mutating func decode(with rangeDecoder: inout LZMARangeDecoder) -> Int {
var m = 1
for _ in 0.. Int {
+ mutating func reverseDecode(with rangeDecoder: inout LZMARangeDecoder) -> Int {
return LZMABitTreeDecoder.bitTreeReverseDecode(probs: &self.probs,
startIndex: 0,
- bits: self.numBits, rangeDecoder)
+ bits: self.numBits, &rangeDecoder)
}
static func bitTreeReverseDecode(probs: inout [Int], startIndex: Int, bits: Int,
- _ rangeDecoder: LZMARangeDecoder) -> Int {
+ _ rangeDecoder: inout LZMARangeDecoder) -> Int {
var m = 1
var symbol = 0
for i in 0.. Int {
+ mutating func decode(with rangeDecoder: inout LZMARangeDecoder, posState: Int) -> Int {
// There can be one of three options.
// We need one or two bits to find out which decoding scheme to use.
// `choice` is used to decode first bit.
// `choice2` is used to decode second bit.
// If binary sequence starts with 0 then:
if rangeDecoder.decode(bitWithProb: &self.choice) == 0 {
- return self.lowCoder[posState].decode(with: rangeDecoder)
+ return self.lowCoder[posState].decode(with: &rangeDecoder)
}
// If binary sequence starts with 1 0 then:
if rangeDecoder.decode(bitWithProb: &self.choice2) == 0 {
- return 8 + self.midCoder[posState].decode(with: rangeDecoder)
+ return 8 + self.midCoder[posState].decode(with: &rangeDecoder)
}
// If binary sequence starts with 1 1 then:
- return 16 + self.highCoder.decode(with: rangeDecoder)
+ return 16 + self.highCoder.decode(with: &rangeDecoder)
}
}
diff --git a/Sources/LZMA/LZMARangeDecoder.swift b/Sources/LZMA/LZMARangeDecoder.swift
index 6cb55561..610fffcf 100644
--- a/Sources/LZMA/LZMARangeDecoder.swift
+++ b/Sources/LZMA/LZMARangeDecoder.swift
@@ -6,9 +6,9 @@
import Foundation
import BitByteData
-final class LZMARangeDecoder {
+struct LZMARangeDecoder {
- private var byteReader: LittleEndianByteReader
+ private let byteReader: LittleEndianByteReader
private var range = 0xFFFFFFFF as UInt32
private var code = 0 as UInt32
@@ -18,10 +18,10 @@ final class LZMARangeDecoder {
return self.code == 0
}
- init?(_ byteReader: LittleEndianByteReader) {
+ init(_ byteReader: LittleEndianByteReader) throws {
// To initialize rande decoder at least 5 bytes are necessary.
guard byteReader.bytesLeft >= 5
- else { return nil }
+ else { throw LZMAError.rangeDecoderInitError }
self.byteReader = byteReader
@@ -29,9 +29,8 @@ final class LZMARangeDecoder {
for _ in 0..<4 {
self.code = (self.code << 8) | UInt32(self.byteReader.byte())
}
- if byte != 0 || self.code == self.range {
- return nil
- }
+ guard byte == 0 && self.code != self.range
+ else { throw LZMAError.rangeDecoderInitError }
}
init() {
@@ -39,15 +38,15 @@ final class LZMARangeDecoder {
}
/// `range` property cannot be smaller than `(1 << 24)`. This function keeps it bigger.
- func normalize() {
- if self.range < UInt32(LZMAConstants.topValue) {
+ mutating func normalize() {
+ if self.range < LZMAConstants.topValue {
self.range <<= 8
self.code = (self.code << 8) | UInt32(byteReader.byte())
}
}
/// Decodes sequence of direct bits (binary symbols with fixed and equal probabilities).
- func decode(directBits: Int) -> Int {
+ mutating func decode(directBits: Int) -> Int {
var res: UInt32 = 0
var count = directBits
repeat {
@@ -70,7 +69,7 @@ final class LZMARangeDecoder {
}
/// Decodes binary symbol (bit) with predicted (estimated) probability.
- func decode(bitWithProb prob: inout Int) -> Int {
+ mutating func decode(bitWithProb prob: inout Int) -> Int {
let bound = (self.range >> UInt32(LZMAConstants.numBitModelTotalBits)) * UInt32(prob)
let symbol: Int
if self.code < bound {
diff --git a/Sources/LZMA2/LZMA2.swift b/Sources/LZMA2/LZMA2.swift
index ff0d8413..cafa914b 100644
--- a/Sources/LZMA2/LZMA2.swift
+++ b/Sources/LZMA2/LZMA2.swift
@@ -28,7 +28,7 @@ public class LZMA2: DecompressionAlgorithm {
}
static func decompress(_ byteReader: LittleEndianByteReader, _ dictSizeByte: UInt8) throws -> Data {
- let decoder = try LZMA2Decoder(byteReader, dictSizeByte)
+ var decoder = try LZMA2Decoder(byteReader, dictSizeByte)
try decoder.decode()
return Data(decoder.out)
}
diff --git a/Sources/LZMA2/LZMA2Decoder.swift b/Sources/LZMA2/LZMA2Decoder.swift
index cfff730f..897dd19c 100644
--- a/Sources/LZMA2/LZMA2Decoder.swift
+++ b/Sources/LZMA2/LZMA2Decoder.swift
@@ -6,10 +6,10 @@
import Foundation
import BitByteData
-final class LZMA2Decoder {
+struct LZMA2Decoder {
private let byteReader: LittleEndianByteReader
- private let decoder: LZMADecoder
+ private var decoder: LZMADecoder
var out: [UInt8] {
return self.decoder.out
@@ -32,7 +32,7 @@ final class LZMA2Decoder {
}
/// Main LZMA2 decoder function.
- func decode() throws {
+ mutating func decode() throws {
mainLoop: while true {
let controlByte = byteReader.byte()
switch controlByte {
@@ -54,7 +54,7 @@ final class LZMA2Decoder {
}
/// Function which dispatches LZMA2 decoding process based on `controlByte`.
- private func dispatch(_ controlByte: UInt8) throws {
+ private mutating func dispatch(_ controlByte: UInt8) throws {
let uncompressedSizeBits = controlByte & 0x1F
let reset = (controlByte & 0x60) >> 5
let unpackSize = (uncompressedSizeBits.toInt() << 16) +
@@ -82,7 +82,7 @@ final class LZMA2Decoder {
else { throw LZMA2Error.wrongSizes }
}
- private func decodeUncompressed() {
+ private mutating func decodeUncompressed() {
let dataSize = self.byteReader.byte().toInt() << 8 + self.byteReader.byte().toInt() + 1
for _ in 0..