From c9e113e0e2fc767ce0719e589e4363b9fd93254c Mon Sep 17 00:00:00 2001 From: Eneko Alonso Date: Mon, 11 Jul 2022 18:00:17 -0700 Subject: [PATCH 01/12] Add support for managing the size of the history buffer --- Sources/Gzip/Data+Gzip.swift | 13 +++++++++++-- Tests/GzipTests/GzipTests.swift | 21 ++++++++++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/Sources/Gzip/Data+Gzip.swift b/Sources/Gzip/Data+Gzip.swift index b66ed5d..6caa5fe 100644 --- a/Sources/Gzip/Data+Gzip.swift +++ b/Sources/Gzip/Data+Gzip.swift @@ -211,9 +211,18 @@ extension Data { /// Create a new `Data` instance by decompressing the receiver using zlib. /// Throws an error if decompression failed. /// + /// The `wBits` parameter allows for managing the size of the history buffer. The possible values are: + /// + /// Value Window size logarithm Input + /// +8 to +15 Base 2 Includes zlib header and trailer + /// -8 to -15 Absolute value of wbits Raw stream with no header and trailer + /// +24 to +31 = 16 + (8 to 15) Low 4 bits of the value Includes gzip header and trailer + /// +40 to +47 = 32 + (8 to 15) Low 4 bits of the value zlib or gzip format + /// + /// - Parameter wBits: Manage the size of the history buffer. /// - Returns: Gzip-decompressed `Data` instance. /// - Throws: `GzipError` - public func gunzipped() throws -> Data { + public func gunzipped(wBits: Int32 = MAX_WBITS + 32) throws -> Data { guard !self.isEmpty else { return Data() @@ -222,7 +231,7 @@ extension Data { var stream = z_stream() var status: Int32 - status = inflateInit2_(&stream, MAX_WBITS + 32, ZLIB_VERSION, Int32(DataSize.stream)) + status = inflateInit2_(&stream, wBits, ZLIB_VERSION, Int32(DataSize.stream)) guard status == Z_OK else { // inflateInit2 returns: diff --git a/Tests/GzipTests/GzipTests.swift b/Tests/GzipTests/GzipTests.swift index f020293..21f9131 100644 --- a/Tests/GzipTests/GzipTests.swift +++ b/Tests/GzipTests/GzipTests.swift @@ -30,6 +30,11 @@ import XCTest import Gzip +#if os(Linux) + import zlibLinux +#else + import zlib +#endif final class GzipTests: XCTestCase { @@ -96,7 +101,21 @@ final class GzipTests: XCTestCase { XCTAssertTrue(data.isGzipped) XCTAssertEqual(String(data: uncompressed, encoding: .utf8), "test") } - + + func testDecompressionWithNoHeaderAndTrailer() throws { + let encoded = """ + 7ZOxCsIwEIbf5ea0JNerqdmdFeygFYciHYK0lTZOIe9u9AXMTTpkOQ\ + h8hLv/7vNwmFfr7DyBuXho7Tisrh8fYAAlYiF1oWSr0EgyhCWRrpsa\ + OxCwm9xihxWMB/UuR9e7Z3zCfmqX/naPyAmMFHD+1C7WIKBKRykdrd\ + PRTTqqJINlZKAYkylOv006i4zZEBksY8HIyKFi5EuMf0kzroxzZowc\ + dHIPIYjvjjbRUSTKjmZHs6N/6WhVStS01VnRrGhW9BeKXsML + """ + let data = try XCTUnwrap(Data(base64Encoded: encoded)) + let uncompressed = try data.gunzipped(wBits: -MAX_WBITS) + let json = String(data: uncompressed, encoding: .utf8) + XCTAssertEqual(json?.first, "{") + XCTAssertEqual(json?.last, "}") + } } From c86f068b957ebf2aab80a4f0e1475128ccf8a669 Mon Sep 17 00:00:00 2001 From: Eneko Alonso Date: Mon, 11 Jul 2022 18:05:01 -0700 Subject: [PATCH 02/12] Add support for managing the size of the history buffer when compressing --- Sources/Gzip/Data+Gzip.swift | 19 +++++++++++++++++-- Tests/GzipTests/GzipTests.swift | 5 ----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Sources/Gzip/Data+Gzip.swift b/Sources/Gzip/Data+Gzip.swift index 6caa5fe..dabd91c 100644 --- a/Sources/Gzip/Data+Gzip.swift +++ b/Sources/Gzip/Data+Gzip.swift @@ -34,6 +34,12 @@ import struct Foundation.Data import zlib #endif +#if os(Linux) + public let MAX_WBITS = zliblinux.MAX_WBITS +#else + public let MAX_WBITS = zlib.MAX_WBITS +#endif + /// Compression level whose rawValue is based on the zlib's constants. public struct CompressionLevel: RawRepresentable { @@ -148,10 +154,19 @@ extension Data { /// Create a new `Data` instance by compressing the receiver using zlib. /// Throws an error if compression failed. /// + /// The `wBits` parameter allows for managing the size of the history buffer. The possible values are: + /// + /// Value Window size logarithm Input + /// +8 to +15 Base 2 Includes zlib header and trailer + /// -8 to -15 Absolute value of wbits Raw stream with no header and trailer + /// +24 to +31 = 16 + (8 to 15) Low 4 bits of the value Includes gzip header and trailer + /// +40 to +47 = 32 + (8 to 15) Low 4 bits of the value zlib or gzip format + /// /// - Parameter level: Compression level. + /// - Parameter wBits: Manage the size of the history buffer. /// - Returns: Gzip-compressed `Data` instance. /// - Throws: `GzipError` - public func gzipped(level: CompressionLevel = .defaultCompression) throws -> Data { + public func gzipped(level: CompressionLevel = .defaultCompression, wBits: Int32 = MAX_WBITS + 16) throws -> Data { guard !self.isEmpty else { return Data() @@ -160,7 +175,7 @@ extension Data { var stream = z_stream() var status: Int32 - status = deflateInit2_(&stream, level.rawValue, Z_DEFLATED, MAX_WBITS + 16, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY, ZLIB_VERSION, Int32(DataSize.stream)) + status = deflateInit2_(&stream, level.rawValue, Z_DEFLATED, wBits, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY, ZLIB_VERSION, Int32(DataSize.stream)) guard status == Z_OK else { // deflateInit2 returns: diff --git a/Tests/GzipTests/GzipTests.swift b/Tests/GzipTests/GzipTests.swift index 21f9131..8f610ea 100644 --- a/Tests/GzipTests/GzipTests.swift +++ b/Tests/GzipTests/GzipTests.swift @@ -30,11 +30,6 @@ import XCTest import Gzip -#if os(Linux) - import zlibLinux -#else - import zlib -#endif final class GzipTests: XCTestCase { From f41d56a04c0cdf26b07ed774d0fcb3a06053f1af Mon Sep 17 00:00:00 2001 From: Eneko Alonso Date: Mon, 11 Jul 2022 18:18:00 -0700 Subject: [PATCH 03/12] Fix docs --- Sources/Gzip/Data+Gzip.swift | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Sources/Gzip/Data+Gzip.swift b/Sources/Gzip/Data+Gzip.swift index dabd91c..6aef48d 100644 --- a/Sources/Gzip/Data+Gzip.swift +++ b/Sources/Gzip/Data+Gzip.swift @@ -156,11 +156,10 @@ extension Data { /// /// The `wBits` parameter allows for managing the size of the history buffer. The possible values are: /// - /// Value Window size logarithm Input - /// +8 to +15 Base 2 Includes zlib header and trailer - /// -8 to -15 Absolute value of wbits Raw stream with no header and trailer - /// +24 to +31 = 16 + (8 to 15) Low 4 bits of the value Includes gzip header and trailer - /// +40 to +47 = 32 + (8 to 15) Low 4 bits of the value zlib or gzip format + /// Value Window size logarithm Input + /// +9 to +15 Base 2 Includes zlib header and trailer + /// -9 to -15 Absolute value of wbits No header and trailer + /// +25 to +31 Low 4 bits of the value Includes gzip header and trailing checksum /// /// - Parameter level: Compression level. /// - Parameter wBits: Manage the size of the history buffer. From d17502bd960b895330b940569c80680e2e99f29f Mon Sep 17 00:00:00 2001 From: 1024jp <1024jp@wolfrosch.com> Date: Mon, 18 Jul 2022 22:38:05 +0900 Subject: [PATCH 04/12] Update Xcode project --- Gzip.xcodeproj/project.pbxproj | 31 +++++++++++++++++-- .../xcshareddata/xcschemes/Gzip iOS.xcscheme | 2 +- .../xcschemes/Gzip macOS.xcscheme | 2 +- .../xcshareddata/xcschemes/Gzip tvOS.xcscheme | 2 +- .../xcschemes/Gzip watchOS.xcscheme | 2 +- 5 files changed, 32 insertions(+), 7 deletions(-) diff --git a/Gzip.xcodeproj/project.pbxproj b/Gzip.xcodeproj/project.pbxproj index 15cac13..63500f1 100644 --- a/Gzip.xcodeproj/project.pbxproj +++ b/Gzip.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 51; + objectVersion = 54; objects = { /* Begin PBXAggregateTarget section */ @@ -367,7 +367,7 @@ attributes = { LastSwiftMigration = 0700; LastSwiftUpdateCheck = 1120; - LastUpgradeCheck = 1330; + LastUpgradeCheck = 1400; TargetAttributes = { 2A2CCF79238127CB00FAC851 = { CreatedOnToolsVersion = 11.2.1; @@ -461,6 +461,7 @@ /* Begin PBXShellScriptBuildPhase section */ 2ACC21C31E54BB9D0078241F /* Run Script */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); @@ -471,7 +472,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"SwiftLint does not exist, download from https://github.com/realm/SwiftLint\"\nfi"; + shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"SwiftLint does not exist, download from https://github.com/realm/SwiftLint\"\nfi\n"; }; /* End PBXShellScriptBuildPhase section */ @@ -563,6 +564,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); + MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; PRODUCT_BUNDLE_IDENTIFIER = "com.wolfrosch.Test-tvOS"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; @@ -579,6 +581,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); + MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; PRODUCT_BUNDLE_IDENTIFIER = "com.wolfrosch.Test-tvOS"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; @@ -609,6 +612,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); + MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; MARKETING_VERSION = 5.2.0; OTHER_CFLAGS = "-fembed-bitcode-marker"; PRODUCT_BUNDLE_IDENTIFIER = com.wolfrosch.Gzip; @@ -640,6 +644,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); + MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; MARKETING_VERSION = 5.2.0; OTHER_CFLAGS = "-fembed-bitcode"; PRODUCT_BUNDLE_IDENTIFIER = com.wolfrosch.Gzip; @@ -674,6 +679,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); + MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; MARKETING_VERSION = 5.2.0; OTHER_CFLAGS = "-fembed-bitcode-marker"; PRODUCT_BUNDLE_IDENTIFIER = com.wolfrosch.Gzip; @@ -705,6 +711,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); + MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; MARKETING_VERSION = 5.2.0; OTHER_CFLAGS = "-fembed-bitcode"; PRODUCT_BUNDLE_IDENTIFIER = com.wolfrosch.Gzip; @@ -748,6 +755,7 @@ COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = NO; CURRENT_PROJECT_VERSION = 4; + DEAD_CODE_STRIPPING = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; @@ -808,6 +816,7 @@ COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = NO; CURRENT_PROJECT_VERSION = 4; + DEAD_CODE_STRIPPING = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -833,6 +842,7 @@ 2A58A75F1B00F414005FBBC2 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + DEAD_CODE_STRIPPING = YES; DEBUG_INFORMATION_FORMAT = dwarf; FRAMEWORK_SEARCH_PATHS = ( "$(DEVELOPER_FRAMEWORKS_DIR)", @@ -844,6 +854,7 @@ "@executable_path/../Frameworks", "@loader_path/../Frameworks", ); + MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; PRODUCT_BUNDLE_IDENTIFIER = "com.wolfrosch.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; @@ -853,6 +864,7 @@ 2A58A7601B00F414005FBBC2 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + DEAD_CODE_STRIPPING = YES; FRAMEWORK_SEARCH_PATHS = ( "$(DEVELOPER_FRAMEWORKS_DIR)", "$(inherited)", @@ -863,6 +875,7 @@ "@executable_path/../Frameworks", "@loader_path/../Frameworks", ); + MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; PRODUCT_BUNDLE_IDENTIFIER = "com.wolfrosch.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; @@ -878,6 +891,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); + MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; PRODUCT_BUNDLE_IDENTIFIER = "com.wolfrosch.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; @@ -893,6 +907,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); + MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; PRODUCT_BUNDLE_IDENTIFIER = "com.wolfrosch.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; @@ -903,6 +918,8 @@ 2ACC21C11E54BB920078241F /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + DEAD_CODE_STRIPPING = YES; + MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Debug; @@ -910,6 +927,8 @@ 2ACC21C21E54BB920078241F /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + DEAD_CODE_STRIPPING = YES; + MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -919,6 +938,7 @@ buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; CURRENT_PROJECT_VERSION = 5; + DEAD_CODE_STRIPPING = YES; DEBUG_INFORMATION_FORMAT = dwarf; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = ""; @@ -935,6 +955,7 @@ "@executable_path/../Frameworks", "@loader_path/Frameworks", ); + MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; MARKETING_VERSION = 5.2.0; PRODUCT_BUNDLE_IDENTIFIER = com.wolfrosch.Gzip; PRODUCT_NAME = Gzip; @@ -948,6 +969,7 @@ buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; CURRENT_PROJECT_VERSION = 5; + DEAD_CODE_STRIPPING = YES; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; @@ -962,6 +984,7 @@ "@executable_path/../Frameworks", "@loader_path/Frameworks", ); + MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; MARKETING_VERSION = 5.2.0; PRODUCT_BUNDLE_IDENTIFIER = com.wolfrosch.Gzip; PRODUCT_NAME = Gzip; @@ -991,6 +1014,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); + MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; MARKETING_VERSION = 5.2.0; OTHER_CFLAGS = "-fembed-bitcode-marker"; PRODUCT_BUNDLE_IDENTIFIER = com.wolfrosch.Gzip; @@ -1020,6 +1044,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); + MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; MARKETING_VERSION = 5.2.0; OTHER_CFLAGS = "-fembed-bitcode"; PRODUCT_BUNDLE_IDENTIFIER = com.wolfrosch.Gzip; diff --git a/Gzip.xcodeproj/xcshareddata/xcschemes/Gzip iOS.xcscheme b/Gzip.xcodeproj/xcshareddata/xcschemes/Gzip iOS.xcscheme index 69da53c..23d47ae 100644 --- a/Gzip.xcodeproj/xcshareddata/xcschemes/Gzip iOS.xcscheme +++ b/Gzip.xcodeproj/xcshareddata/xcschemes/Gzip iOS.xcscheme @@ -1,6 +1,6 @@ Date: Mon, 18 Jul 2022 22:46:19 +0900 Subject: [PATCH 05/12] Update .swiftlint.yml --- .swiftlint.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index 9018928..878a7c4 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -1,6 +1,9 @@ excluded: - Tests/GzipTests + +disabled_rules: + - identifier_name opt_in_rules: - attributes @@ -11,7 +14,6 @@ opt_in_rules: - explicit_init - fatal_error_message - first_where - - implicit_return - implicitly_unwrapped_optional - let_var_whitespace - multiline_parameters From e298d3a3b876b8134f651e38bd84eaec148f2542 Mon Sep 17 00:00:00 2001 From: 1024jp <1024jp@wolfrosch.com> Date: Mon, 18 Jul 2022 22:50:42 +0900 Subject: [PATCH 06/12] Remove deprecated option in CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4383f2d..e9dd5d2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Unit Test - run: swift test --enable-test-discovery + run: swift test xcode: name: Test with Xcode From 0ba8c45a8bea5d41d00c17a56aefb8b7af0ddbaa Mon Sep 17 00:00:00 2001 From: 1024jp <1024jp@wolfrosch.com> Date: Mon, 18 Jul 2022 23:03:56 +0900 Subject: [PATCH 07/12] Fix CI test --- .github/workflows/ci.yml | 8 ++++---- Gzip.xcodeproj/project.pbxproj | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e9dd5d2..8a231c3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,7 +5,7 @@ on: [push, pull_request] jobs: macOS: name: Test on macOS - runs-on: macOS-latest + runs-on: macOS-12 steps: - uses: actions/checkout@v1 - name: Show environments @@ -23,7 +23,7 @@ jobs: run: pod lib lint --quick linux: runs-on: ubuntu-latest - container: swift:5.4-focal + container: swift:latest steps: - uses: actions/checkout@v2 - name: Unit Test @@ -31,7 +31,7 @@ jobs: xcode: name: Test with Xcode - runs-on: macOS-latest + runs-on: macos-12 strategy: matrix: name: [macOS, iOS, tvOS] @@ -47,7 +47,7 @@ jobs: - name: tvOS scheme: Gzip tvOS sdk: appletvsimulator - destination: 'platform=tvOS Simulator,name=Apple TV 4K' + destination: 'platform=tvOS Simulator,name=Apple TV' steps: - uses: actions/checkout@v1 - name: Test diff --git a/Gzip.xcodeproj/project.pbxproj b/Gzip.xcodeproj/project.pbxproj index 63500f1..2680342 100644 --- a/Gzip.xcodeproj/project.pbxproj +++ b/Gzip.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 54; + objectVersion = 55; objects = { /* Begin PBXAggregateTarget section */ @@ -407,7 +407,7 @@ }; }; buildConfigurationList = 2A58A7501B00F3A2005FBBC2 /* Build configuration list for PBXProject "Gzip" */; - compatibilityVersion = "Xcode 10.0"; + compatibilityVersion = "Xcode 13.0"; developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( @@ -773,7 +773,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; INFOPLIST_KEY_NSHumanReadableCopyright = "© 2014-2022 1024jp"; IPHONEOS_DEPLOYMENT_TARGET = 12.0; - MACOSX_DEPLOYMENT_TARGET = 10.9; + MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; MARKETING_VERSION = 5.1.1; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; @@ -829,7 +829,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; INFOPLIST_KEY_NSHumanReadableCopyright = "© 2014-2022 1024jp"; IPHONEOS_DEPLOYMENT_TARGET = 12.0; - MACOSX_DEPLOYMENT_TARGET = 10.9; + MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; MARKETING_VERSION = 5.1.1; MTL_ENABLE_DEBUG_INFO = NO; SWIFT_COMPILATION_MODE = wholemodule; From 2e44dff8f00cadc1b036b9359011c66f1acf83ec Mon Sep 17 00:00:00 2001 From: Eneko Alonso Date: Mon, 18 Jul 2022 08:58:57 -0700 Subject: [PATCH 08/12] Rename public variable to --- Sources/Gzip/Data+Gzip.swift | 7 ++----- Tests/GzipTests/GzipTests.swift | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Sources/Gzip/Data+Gzip.swift b/Sources/Gzip/Data+Gzip.swift index 6aef48d..d41754d 100644 --- a/Sources/Gzip/Data+Gzip.swift +++ b/Sources/Gzip/Data+Gzip.swift @@ -34,11 +34,8 @@ import struct Foundation.Data import zlib #endif -#if os(Linux) - public let MAX_WBITS = zliblinux.MAX_WBITS -#else - public let MAX_WBITS = zlib.MAX_WBITS -#endif +/// Maximum value for windowBits (`MAX_WBITS`) +public let maxWindowBits = MAX_WBITS /// Compression level whose rawValue is based on the zlib's constants. public struct CompressionLevel: RawRepresentable { diff --git a/Tests/GzipTests/GzipTests.swift b/Tests/GzipTests/GzipTests.swift index 8f610ea..8a9b0ad 100644 --- a/Tests/GzipTests/GzipTests.swift +++ b/Tests/GzipTests/GzipTests.swift @@ -106,7 +106,7 @@ final class GzipTests: XCTestCase { dHIPIYjvjjbRUSTKjmZHs6N/6WhVStS01VnRrGhW9BeKXsML """ let data = try XCTUnwrap(Data(base64Encoded: encoded)) - let uncompressed = try data.gunzipped(wBits: -MAX_WBITS) + let uncompressed = try data.gunzipped(wBits: -maxWindowBits) let json = String(data: uncompressed, encoding: .utf8) XCTAssertEqual(json?.first, "{") XCTAssertEqual(json?.last, "}") From e7d32ea2688fd0e284c71cb24b796dd1a56d3e11 Mon Sep 17 00:00:00 2001 From: 1024jp <1024jp@wolfrosch.com> Date: Tue, 19 Jul 2022 13:06:51 +0900 Subject: [PATCH 09/12] Update .swiftlint.yml --- .swiftlint.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index 878a7c4..6480b55 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -1,9 +1,6 @@ excluded: - Tests/GzipTests - -disabled_rules: - - identifier_name opt_in_rules: - attributes From 241bb44bed9d0002d17eeb1dd50d989ff33a89e9 Mon Sep 17 00:00:00 2001 From: 1024jp <1024jp@wolfrosch.com> Date: Tue, 19 Jul 2022 13:11:35 +0900 Subject: [PATCH 10/12] Use .swiftlint also for unit test code --- .swiftlint.yml | 7 +------ Tests/GzipTests/GzipTests.swift | 6 +++++- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index 6480b55..54c6dd5 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -1,7 +1,4 @@ -excluded: - - Tests/GzipTests - opt_in_rules: - attributes - closure_end_indentation @@ -15,7 +12,6 @@ opt_in_rules: - let_var_whitespace - multiline_parameters - nimble_operator - - no_extension_access_modifier - number_separator - object_literal - operator_usage_whitespace @@ -23,7 +19,6 @@ opt_in_rules: - redundant_nil_coalescing - strict_fileprivate - switch_case_on_newline - - unneeded_parentheses_in_closure_argument - vertical_parameter_alignment_on_call trailing_comma: @@ -33,6 +28,6 @@ trailing_whitespace: ignores_empty_lines: true vertical_whitespace: - max_empty_lines: 2 + max_empty_lines: 3 line_length: 200 diff --git a/Tests/GzipTests/GzipTests.swift b/Tests/GzipTests/GzipTests.swift index 8a9b0ad..c636f4f 100644 --- a/Tests/GzipTests/GzipTests.swift +++ b/Tests/GzipTests/GzipTests.swift @@ -69,7 +69,9 @@ final class GzipTests: XCTestCase { let data = "testString".data(using: .utf8)! XCTAssertThrowsError(try data.gunzipped()) { error in - guard let gzipError = error as? GzipError else { return XCTFail("Caught incorrect error.") } + guard let gzipError = error as? GzipError else { + return XCTFail("Caught incorrect error.") + } XCTAssertEqual(gzipError.kind, .data) XCTAssertEqual(gzipError.message, "incorrect header check") @@ -98,6 +100,7 @@ final class GzipTests: XCTestCase { } func testDecompressionWithNoHeaderAndTrailer() throws { + let encoded = """ 7ZOxCsIwEIbf5ea0JNerqdmdFeygFYciHYK0lTZOIe9u9AXMTTpkOQ\ h8hLv/7vNwmFfr7DyBuXho7Tisrh8fYAAlYiF1oWSr0EgyhCWRrpsa\ @@ -108,6 +111,7 @@ final class GzipTests: XCTestCase { let data = try XCTUnwrap(Data(base64Encoded: encoded)) let uncompressed = try data.gunzipped(wBits: -maxWindowBits) let json = String(data: uncompressed, encoding: .utf8) + XCTAssertEqual(json?.first, "{") XCTAssertEqual(json?.last, "}") } From df506dc7f25cef090b73f31069d211469fab9947 Mon Sep 17 00:00:00 2001 From: 1024jp <1024jp@wolfrosch.com> Date: Tue, 19 Jul 2022 13:18:42 +0900 Subject: [PATCH 11/12] Wrap maxWindowBits with Gzip (#52) --- Sources/Gzip/Data+Gzip.swift | 12 ++++++++---- Tests/GzipTests/GzipTests.swift | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Sources/Gzip/Data+Gzip.swift b/Sources/Gzip/Data+Gzip.swift index d41754d..1f9c6c5 100644 --- a/Sources/Gzip/Data+Gzip.swift +++ b/Sources/Gzip/Data+Gzip.swift @@ -34,8 +34,12 @@ import struct Foundation.Data import zlib #endif -/// Maximum value for windowBits (`MAX_WBITS`) -public let maxWindowBits = MAX_WBITS +public enum Gzip { + + /// Maximum value for windowBits (`MAX_WBITS`) + public static let maxWindowBits = MAX_WBITS +} + /// Compression level whose rawValue is based on the zlib's constants. public struct CompressionLevel: RawRepresentable { @@ -162,7 +166,7 @@ extension Data { /// - Parameter wBits: Manage the size of the history buffer. /// - Returns: Gzip-compressed `Data` instance. /// - Throws: `GzipError` - public func gzipped(level: CompressionLevel = .defaultCompression, wBits: Int32 = MAX_WBITS + 16) throws -> Data { + public func gzipped(level: CompressionLevel = .defaultCompression, wBits: Int32 = Gzip.maxWindowBits + 16) throws -> Data { guard !self.isEmpty else { return Data() @@ -233,7 +237,7 @@ extension Data { /// - Parameter wBits: Manage the size of the history buffer. /// - Returns: Gzip-decompressed `Data` instance. /// - Throws: `GzipError` - public func gunzipped(wBits: Int32 = MAX_WBITS + 32) throws -> Data { + public func gunzipped(wBits: Int32 = Gzip.maxWindowBits + 32) throws -> Data { guard !self.isEmpty else { return Data() diff --git a/Tests/GzipTests/GzipTests.swift b/Tests/GzipTests/GzipTests.swift index c636f4f..c7b0dab 100644 --- a/Tests/GzipTests/GzipTests.swift +++ b/Tests/GzipTests/GzipTests.swift @@ -109,7 +109,7 @@ final class GzipTests: XCTestCase { dHIPIYjvjjbRUSTKjmZHs6N/6WhVStS01VnRrGhW9BeKXsML """ let data = try XCTUnwrap(Data(base64Encoded: encoded)) - let uncompressed = try data.gunzipped(wBits: -maxWindowBits) + let uncompressed = try data.gunzipped(wBits: -Gzip.maxWindowBits) let json = String(data: uncompressed, encoding: .utf8) XCTAssertEqual(json?.first, "{") From e99ced22d05d7933377cd24cc147651f58948a65 Mon Sep 17 00:00:00 2001 From: 1024jp <1024jp@wolfrosch.com> Date: Tue, 19 Jul 2022 13:03:20 +0900 Subject: [PATCH 12/12] Update to 5.3.0 --- CHANGELOG.md | 9 +++++++++ GzipSwift.podspec | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cde2c08..d30584b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ Change Log ========================== +5.3.0 +-------------------------- + +### Changes + +- add `wBits` optional parameter to `gzipped(level:)` and `.gunzipped()` to support managing the size of the history buffer. + + + 5.2.0 -------------------------- diff --git a/GzipSwift.podspec b/GzipSwift.podspec index bf2959c..d3b173f 100644 --- a/GzipSwift.podspec +++ b/GzipSwift.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "GzipSwift" - s.version = "5.2.0" + s.version = "5.3.0" s.swift_version = '5.0' s.summary = "Swift framework that enables gzip/gunzip Data using zlib."