Skip to content

Commit

Permalink
Merge branch 'release/4.0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
1024jp committed Nov 11, 2017
2 parents 88a1cf9 + 3745a2c commit b6df9ea
Show file tree
Hide file tree
Showing 12 changed files with 145 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: objective-c
osx_image: xcode9
osx_image: xcode9.1

matrix:
include:
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------------------

Expand Down
17 changes: 14 additions & 3 deletions Gzip.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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; };
Expand Down Expand Up @@ -183,7 +184,8 @@
children = (
2A58A7611B00F42C005FBBC2 /* Data+Gzip.swift */,
);
path = Sources;
name = Sources;
path = Sources/Gzip;
sourceTree = "<group>";
};
2A58A7661B00F5CF005FBBC2 /* Libraries */ = {
Expand All @@ -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 = (
Expand Down
2 changes: 1 addition & 1 deletion GzipSwift.podspec
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
11 changes: 10 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -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"]),
]
)
2 changes: 1 addition & 1 deletion Project/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand All @@ -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
Expand Down
41 changes: 23 additions & 18 deletions Sources/Data+Gzip.swift → Sources/Gzip/Data+Gzip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions Sources/system-zlib/anchor.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// intentionally empty
6 changes: 6 additions & 0 deletions Sources/system-zlib/include/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module zlibLinux [system] {
header "/usr/include/zlib.h"
header "/usr/include/zconf.h"
link "z"
export *
}
79 changes: 53 additions & 26 deletions Tests/GzipTests/GzipTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
48 changes: 24 additions & 24 deletions Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit b6df9ea

Please sign in to comment.