Merge branch 'release/4.0.3'
This commit is contained in:
commit
b6df9ea639
|
@ -1,5 +1,5 @@
|
|||
language: objective-c
|
||||
osx_image: xcode9
|
||||
osx_image: xcode9.1
|
||||
|
||||
matrix:
|
||||
include:
|
||||
|
|
|
@ -2,6 +2,15 @@
|
|||
Change Log
|
||||
==========================
|
||||
|
||||
4.0.3
|
||||
--------------------------
|
||||
|
||||
### Fixes
|
||||
|
||||
- Fix running on Linux.
|
||||
- Fix a runtime crash with Xcode 9.1.
|
||||
|
||||
|
||||
4.0.2
|
||||
--------------------------
|
||||
|
||||
|
|
|
@ -63,9 +63,10 @@
|
|||
2A321F071D4A635F002B0245 /* Gzip.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Gzip.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
2A321F101D4A6398002B0245 /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/usr/lib/libz.tbd; sourceTree = DEVELOPER_DIR; };
|
||||
2A58A7571B00F414005FBBC2 /* Tests macOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Tests macOS.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
2A58A75C1B00F414005FBBC2 /* GzipTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = GzipTests.swift; path = GzipTests/GzipTests.swift; sourceTree = "<group>"; };
|
||||
2A58A75C1B00F414005FBBC2 /* GzipTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GzipTests.swift; sourceTree = "<group>"; };
|
||||
2A58A7611B00F42C005FBBC2 /* Data+Gzip.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Data+Gzip.swift"; sourceTree = "<group>"; };
|
||||
2A58A77D1B00FBEF005FBBC2 /* Tests iOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Tests iOS.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
2A7DC79D1FB6AFBF00539D90 /* LinuxMain.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinuxMain.swift; sourceTree = "<group>"; };
|
||||
2A8219C61D65AFB300D65063 /* test.txt.gz */ = {isa = PBXFileReference; lastKnownFileType = archive.gzip; path = test.txt.gz; sourceTree = "<group>"; };
|
||||
2AD497381B8E2A2D00AFBA1B /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; };
|
||||
2AD4973A1B8E2A3800AFBA1B /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/libz.tbd; sourceTree = DEVELOPER_DIR; };
|
||||
|
@ -183,7 +184,8 @@
|
|||
children = (
|
||||
2A58A7611B00F42C005FBBC2 /* Data+Gzip.swift */,
|
||||
);
|
||||
path = Sources;
|
||||
name = Sources;
|
||||
path = Sources/Gzip;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
2A58A7661B00F5CF005FBBC2 /* Libraries */ = {
|
||||
|
@ -208,13 +210,22 @@
|
|||
2A58A7881B00FD11005FBBC2 /* Tests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
2A58A75C1B00F414005FBBC2 /* GzipTests.swift */,
|
||||
2A7DC79E1FB6AFC900539D90 /* GzipTests */,
|
||||
2A7DC79D1FB6AFBF00539D90 /* LinuxMain.swift */,
|
||||
2AE050A81D4A33A30040E4C9 /* Info.plist */,
|
||||
2A8219C61D65AFB300D65063 /* test.txt.gz */,
|
||||
);
|
||||
path = Tests;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
2A7DC79E1FB6AFC900539D90 /* GzipTests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
2A58A75C1B00F414005FBBC2 /* GzipTests.swift */,
|
||||
);
|
||||
path = GzipTests;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
2AE050891D4A2C070040E4C9 /* Supporting Files */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = "GzipSwift"
|
||||
s.version = "4.0.2"
|
||||
s.version = "4.0.3"
|
||||
s.summary = "Swift framework that enables gzip/gunzip Data using zlib."
|
||||
|
||||
s.homepage = "https://github.com/1024jp/GzipSwift"
|
||||
|
|
|
@ -1,6 +1,15 @@
|
|||
// swift-tools-version:4.0
|
||||
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "Gzip",
|
||||
dependencies: [.Package(url: "https://github.com/1024jp/zlib.git", versions: Version(0, 0, 0)..<Version(1, 0, 0))]
|
||||
products: [
|
||||
.library(name: "Gzip", targets: ["Gzip"]),
|
||||
],
|
||||
targets: [
|
||||
.target(name: "Gzip", dependencies: ["system-zlib"]),
|
||||
.target(name: "system-zlib"),
|
||||
.testTarget(name: "GzipTests", dependencies: ["Gzip"]),
|
||||
]
|
||||
)
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>4.0.2</string>
|
||||
<string>4.0.3</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>$(CURRENT_PROJECT_VERSION)</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
GzipSwift
|
||||
========================
|
||||
|
||||
[![Swift](https://img.shields.io/badge/Swift-4.0.0-blue.svg)]()
|
||||
[![Swift](https://img.shields.io/badge/Swift-4.0.2-blue.svg)]()
|
||||
[![platform](https://img.shields.io/badge/platform-macOS%20|%20iOS%20|%20watchOS%20|%20tvOS%20|%20Linux-blue.svg)]()
|
||||
[![Carthage compatible](https://img.shields.io/badge/Carthage-✔-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
|
||||
[![SPM compatible](https://img.shields.io/badge/SPM-✔-4BC51D.svg?style=flat)](https://swift.org/package-manager/)
|
||||
|
@ -13,7 +13,7 @@ GzipSwift
|
|||
__GzipSwift__ is a framework with an extension of Data written in Swift. It enables compress/decompress gzip using zlib.
|
||||
|
||||
- __Requirements__: OS X 10.9 / iOS 8 / watchOS 2 / tvOS 9 or later
|
||||
- __Swift version__: Swift 4.0.0
|
||||
- __Swift version__: Swift 4.0.2
|
||||
|
||||
|
||||
## Usage
|
||||
|
|
|
@ -27,7 +27,12 @@
|
|||
*/
|
||||
|
||||
import Foundation
|
||||
import zlib
|
||||
|
||||
#if os(Linux)
|
||||
import zlibLinux
|
||||
#else
|
||||
import zlib
|
||||
#endif
|
||||
|
||||
/**
|
||||
Compression level whose rawValue is based on the zlib's constants.
|
||||
|
@ -163,27 +168,27 @@ extension Data {
|
|||
|
||||
|
||||
/**
|
||||
Create a new `Data` object by compressing the receiver using zlib.
|
||||
Throws an error if compression failed.
|
||||
Create a new `Data` object by compressing the receiver using zlib.
|
||||
Throws an error if compression failed.
|
||||
|
||||
- parameters:
|
||||
- level: Compression level.
|
||||
|
||||
- throws: `GzipError`
|
||||
- returns: Gzip-compressed `Data` object.
|
||||
*/
|
||||
- parameters:
|
||||
- level: Compression level.
|
||||
|
||||
- throws: `GzipError`
|
||||
- returns: Gzip-compressed `Data` object.
|
||||
*/
|
||||
public func gzipped(level: CompressionLevel = .defaultCompression) throws -> Data {
|
||||
|
||||
guard !self.isEmpty else {
|
||||
return Data()
|
||||
}
|
||||
|
||||
let contiguousData = self.withUnsafeBytes {Data(bytes: $0, count: self.count)}
|
||||
let contiguousData = self.withUnsafeBytes { Data(bytes: $0, count: self.count) }
|
||||
var stream = contiguousData.createZStream()
|
||||
var status: Int32
|
||||
|
||||
status = deflateInit2_(&stream, level.rawValue, Z_DEFLATED, MAX_WBITS + 16, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY, ZLIB_VERSION, Int32(DataSize.stream))
|
||||
|
||||
|
||||
guard status == Z_OK else {
|
||||
// deflateInit2 returns:
|
||||
// Z_VERSION_ERROR The zlib library version is incompatible with the version assumed by the caller.
|
||||
|
@ -215,19 +220,19 @@ extension Data {
|
|||
|
||||
|
||||
/**
|
||||
Create a new `Data` object by decompressing the receiver using zlib.
|
||||
Throws an error if decompression failed.
|
||||
|
||||
- throws: `GzipError`
|
||||
- returns: Gzip-decompressed `Data` object.
|
||||
*/
|
||||
Create a new `Data` object by decompressing the receiver using zlib.
|
||||
Throws an error if decompression failed.
|
||||
|
||||
- throws: `GzipError`
|
||||
- returns: Gzip-decompressed `Data` object.
|
||||
*/
|
||||
public func gunzipped() throws -> Data {
|
||||
|
||||
guard !self.isEmpty else {
|
||||
return Data()
|
||||
}
|
||||
|
||||
let contiguousData = self.withUnsafeBytes {Data(bytes: $0, count: self.count)}
|
||||
let contiguousData = self.withUnsafeBytes { Data(bytes: $0, count: self.count) }
|
||||
var stream = contiguousData.createZStream()
|
||||
var status: Int32
|
||||
|
|
@ -0,0 +1 @@
|
|||
// intentionally empty
|
|
@ -0,0 +1,6 @@
|
|||
module zlibLinux [system] {
|
||||
header "/usr/include/zlib.h"
|
||||
header "/usr/include/zconf.h"
|
||||
link "z"
|
||||
export *
|
||||
}
|
|
@ -5,34 +5,43 @@
|
|||
// Created by 1024jp on 2015-05-11.
|
||||
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
© 2015-2017 1024jp
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
The MIT License (MIT)
|
||||
|
||||
© 2015-2017 1024jp
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import XCTest
|
||||
import Gzip
|
||||
|
||||
class GzipTests: XCTestCase {
|
||||
|
||||
static let allTests = [
|
||||
("testGzip", GzipTests.testGZip),
|
||||
("testZeroLength", GzipTests.testZeroLength),
|
||||
("testWrongUngzip", GzipTests.testWrongUngzip),
|
||||
("testCompressionLevel", GzipTests.testCompressionLevel),
|
||||
("testFileDecompression", GzipTests.testFileDecompression),
|
||||
]
|
||||
|
||||
|
||||
func testGZip() {
|
||||
|
||||
let testSentence = "foo"
|
||||
|
@ -95,32 +104,50 @@ class GzipTests: XCTestCase {
|
|||
|
||||
func testFileDecompression() {
|
||||
|
||||
let bundle = Bundle(for: type(of: self))
|
||||
guard let url = bundle.url(forResource: "test.txt", withExtension: "gz") else { return }
|
||||
let url = self.bundleFile(name: "test.txt.gz")
|
||||
let data = try! Data(contentsOf: url)
|
||||
let uncompressed = try! data.gunzipped()
|
||||
|
||||
XCTAssertEqual(String(data: uncompressed, encoding: .utf8), "test")
|
||||
}
|
||||
|
||||
|
||||
/// create URL for bundled test file considering platform
|
||||
private func bundleFile(name: String) -> URL {
|
||||
|
||||
#if SWIFT_PACKAGE
|
||||
return URL(fileURLWithPath: "./Tests/" + name)
|
||||
#else
|
||||
return Bundle(for: type(of: self)).url(forResource: name, withExtension: nil)!
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private extension String {
|
||||
|
||||
/// Generate random letters string for test.
|
||||
static func lorem(length: Int) -> String {
|
||||
|
||||
func random(_ upperBound: Int) -> Int {
|
||||
#if os(Linux)
|
||||
srandom(UInt32(time(nil)))
|
||||
return Int(random(upperBound))
|
||||
#else
|
||||
return Int(arc4random_uniform(UInt32(upperBound)))
|
||||
#endif
|
||||
}
|
||||
|
||||
let letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
|
||||
var string = ""
|
||||
for _ in 0..<length {
|
||||
let rand = Int(arc4random_uniform(UInt32(letters.count)))
|
||||
let rand = random(letters.count)
|
||||
let index = letters.index(letters.startIndex, offsetBy: rand)
|
||||
let character = letters[index]
|
||||
string.append(character)
|
||||
}
|
||||
|
||||
return string
|
||||
}
|
||||
|
||||
|
|
|
@ -1,32 +1,32 @@
|
|||
//
|
||||
// LinuxMain.swift
|
||||
// Gzip
|
||||
// GzipTests
|
||||
//
|
||||
// Created by 1024jp on 2016-11-10.
|
||||
// Created by 1024jp on 2017-11-10.
|
||||
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
© 2016 1024jp
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
The MIT License (MIT)
|
||||
|
||||
© 2017 1024jp
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import XCTest
|
||||
@testable import GzipTests
|
||||
|
|
Loading…
Reference in New Issue