Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
tsolomko committed Nov 22, 2016
2 parents a635c37 + 6938cad commit d0020a2
Show file tree
Hide file tree
Showing 54 changed files with 510 additions and 767 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.bz2 filter=lfs diff=lfs merge=lfs -text
*.deflate filter=lfs diff=lfs merge=lfs -text
*.answer filter=lfs diff=lfs merge=lfs -text
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ env:
before_install:
- brew update
- brew outdated carthage || brew upgrade carthage
- brew install git-lfs
- git lfs install
before_script:
- git lfs pull
before_deploy:
- carthage build --no-skip-current
- carthage archive $FRAMEWORK_NAME
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Changelog
v1.1.2
----------------
- Fixed memory problem in Deflate.
- Improved overall performance.

v1.1.1
----------------
- Fixed problems when building with Swift Package Manager.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import PackageDescription
let package = Package(
name: "PackageName",
dependencies: [
.Package(url: "https://github.com/tsolomko/SWCompression.git")
.Package(url: "https://github.com/tsolomko/SWCompression.git", majorVersion: 1)
]
)
```
Expand Down
2 changes: 1 addition & 1 deletion SWCompression.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "SWCompression"
s.version = "1.1.1"
s.version = "1.1.2"
s.summary = "Framework with implementations in Swift of different (de)compression algorithms"

s.description = <<-DESC
Expand Down
324 changes: 162 additions & 162 deletions SWCompression.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions Sources/DataWithPointer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,19 @@ class DataWithPointer {
return self.bits(count: 1).first!
}

/// Skips until next byte and returns next `count` bytes.
func alignedBytes(count: Int) -> [UInt8] {
self.skipUntilNextByte()
var array: [UInt8] = Array(repeating: 0, count: count)
CFBitVectorGetBits(self.bitVector, CFRangeMake(self.index * 8, count * 8), &array)
self.index += count
return array
}

// MARK: Manipulations with index and bitShift

func skipUntilNextByte() {
guard self.bitShift != 0 else { return }
self.index += 1
self.bitShift = 0
}
Expand Down
5 changes: 2 additions & 3 deletions Sources/Deflate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public class Deflate: DecompressionAlgorithm {

if blockType == [0, 0] { // Uncompressed block.
pointerData.skipUntilNextByte()

/// Length of the uncompressed data.
let length = pointerData.intFromBits(count: 16)
/// 1-complement of the length.
Expand All @@ -65,9 +64,9 @@ public class Deflate: DecompressionAlgorithm {
// TODO: Rename WrongBlockLengths to WrongUncompressedBlockLengths (or something else)
guard length & nlength == 0 else { throw DeflateError.WrongBlockLengths }
// Process uncompressed data into the output
// TODO: Replace precondition with guard and error throwing.
precondition(pointerData.bitShift == 0, "Misaligned byte.")
out.append(contentsOf: data.bytes(from: pointerData.index..<pointerData.index + length))
pointerData.index += length
out.append(contentsOf: pointerData.alignedBytes(count: length))
} else if blockType == [1, 0] || blockType == [0, 1] {
// Block with Huffman coding (either static or dynamic)

Expand Down
14 changes: 11 additions & 3 deletions Sources/GzipArchive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ public class GzipArchive: Archive {
static let fcomment: UInt8 = 0x10
}

struct ServiceInfo {
struct ServiceInfo: Equatable {

let magic: [UInt8]
let method: UInt8
let flags: UInt8
let mtime: UInt64
let mtime: [UInt8]
let extraFlags: UInt8
let osType: UInt8
// Starting point of compressed data. Depends on presence of optional fields.
Expand All @@ -49,6 +50,13 @@ public class GzipArchive: Archive {
var fileName: String
var comment: String
var crc: UInt16

public static func ==(lhs: ServiceInfo, rhs: ServiceInfo) -> Bool {
return lhs.magic == rhs.magic && lhs.method == rhs.method &&
lhs.flags == rhs.flags && lhs.mtime == rhs.mtime && lhs.extraFlags == rhs.extraFlags &&
lhs.osType == rhs.osType && lhs.startPoint == rhs.startPoint &&
lhs.fileName == rhs.fileName && lhs.comment == rhs.comment && lhs.crc == rhs.crc
}
}

static func serviceInfo(archiveData data: Data) throws -> ServiceInfo {
Expand All @@ -64,7 +72,7 @@ public class GzipArchive: Archive {
var serviceInfo = ServiceInfo(magic: magic,
method: method,
flags: data[3],
mtime: Data(data[4...7]).to(type: UInt64.self),
mtime: data.bytes(from: 4..<8),
extraFlags: data[8],
osType: data[9],
startPoint: 10,
Expand Down
2 changes: 1 addition & 1 deletion Sources/Service/Info-iOS.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>1.1.1</string>
<string>1.1.2</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down
2 changes: 1 addition & 1 deletion Sources/Service/Info-tvOS.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>1.1.1</string>
<string>1.1.2</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down
2 changes: 1 addition & 1 deletion Sources/Service/Info-watchOS.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>1.1.1</string>
<string>1.1.2</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down
2 changes: 1 addition & 1 deletion Sources/Service/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>1.1.1</string>
<string>1.1.2</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSHumanReadableCopyright</key>
Expand Down
11 changes: 10 additions & 1 deletion Sources/ZlibArchive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,20 @@ public class ZlibArchive: Archive {
case slowAlgorithm = 3
}

struct ServiceInfo {
struct ServiceInfo: Equatable {

let compressionMethod: UInt8
let windowSize: Int
let compressionLevel: CompressionLevel
var startPoint: Int

public static func ==(lhs: ServiceInfo, rhs: ServiceInfo) -> Bool {
return lhs.compressionMethod == rhs.compressionMethod &&
lhs.windowSize == rhs.windowSize &&
lhs.compressionLevel == rhs.compressionLevel &&
lhs.startPoint == rhs.startPoint
}

}

static func serviceInfo(archiveData data: Data) throws -> ServiceInfo {
Expand Down
160 changes: 160 additions & 0 deletions Tests/DeflateTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
//
// DeflateTests.swift
// SWCompression
//
// Created by Timofey Solomko on 21.11.16.
// Copyright © 2016 Timofey Solomko. All rights reserved.
//

import XCTest
import SWCompression

class DeflateTests: XCTestCase {

static let testType: String = "deflate"

func testDeflate1() {
let testName = "test1"
guard let testData = try? Data(contentsOf: Constants.url(forTest: testName, withType: DeflateTests.testType)) else {
XCTFail("Failed to load test archive")
return
}

guard let decompressedData = try? Deflate.decompress(compressedData: testData) else {
XCTFail("Failed to decompress")
return
}

guard let answerData = try? Data(contentsOf: Constants.url(forAnswer: testName)) else {
XCTFail("Failed to get the answer")
return
}

XCTAssertEqual(decompressedData, answerData, "Decompression was incorrect")
}

func testDeflate2() {
let testName = "test2"
guard let testData = try? Data(contentsOf: Constants.url(forTest: testName, withType: DeflateTests.testType)) else {
XCTFail("Failed to load test archive")
return
}

guard let decompressedData = try? Deflate.decompress(compressedData: testData) else {
XCTFail("Failed to decompress")
return
}

guard let answerData = try? Data(contentsOf: Constants.url(forAnswer: testName)) else {
XCTFail("Failed to get the answer")
return
}

XCTAssertEqual(decompressedData, answerData, "Decompression was incorrect")
}

func testDeflate3() {
let testName = "test3"
guard let testData = try? Data(contentsOf: Constants.url(forTest: testName, withType: DeflateTests.testType)) else {
XCTFail("Failed to load test archive")
return
}

guard let decompressedData = try? Deflate.decompress(compressedData: testData) else {
XCTFail("Failed to decompress")
return
}

guard let answerData = try? Data(contentsOf: Constants.url(forAnswer: testName)) else {
XCTFail("Failed to get the answer")
return
}

XCTAssertEqual(decompressedData, answerData, "Decompression was incorrect")
}


func testDeflate4() {
let testName = "test4"
guard let testData = try? Data(contentsOf: Constants.url(forTest: testName, withType: DeflateTests.testType)) else {
XCTFail("Failed to load test archive")
return
}

guard let decompressedData = try? Deflate.decompress(compressedData: testData) else {
XCTFail("Failed to decompress")
return
}

guard let answerData = try? Data(contentsOf: Constants.url(forAnswer: testName)) else {
XCTFail("Failed to get the answer")
return
}

XCTAssertEqual(decompressedData, answerData, "Decompression was incorrect")
}


func testDeflate5() {
let testName = "test5"
guard let testData = try? Data(contentsOf: Constants.url(forTest: testName, withType: DeflateTests.testType)) else {
XCTFail("Failed to load test archive")
return
}

guard let decompressedData = try? Deflate.decompress(compressedData: testData) else {
XCTFail("Failed to decompress")
return
}

guard let answerData = try? Data(contentsOf: Constants.url(forAnswer: testName)) else {
XCTFail("Failed to get the answer")
return
}

XCTAssertEqual(decompressedData, answerData, "Decompression was incorrect")
}


func testDeflate6() {
let testName = "test6"
guard let testData = try? Data(contentsOf: Constants.url(forTest: testName, withType: DeflateTests.testType)) else {
XCTFail("Failed to load test archive")
return
}

guard let decompressedData = try? Deflate.decompress(compressedData: testData) else {
XCTFail("Failed to decompress")
return
}

guard let answerData = try? Data(contentsOf: Constants.url(forAnswer: testName)) else {
XCTFail("Failed to get the answer")
return
}

XCTAssertEqual(decompressedData, answerData, "Decompression was incorrect")
}


func testDeflate7() {
let testName = "test7"
guard let testData = try? Data(contentsOf: Constants.url(forTest: testName, withType: DeflateTests.testType)) else {
XCTFail("Failed to load test archive")
return
}

guard let decompressedData = try? Deflate.decompress(compressedData: testData) else {
XCTFail("Failed to decompress")
return
}

guard let answerData = try? Data(contentsOf: Constants.url(forAnswer: testName)) else {
XCTFail("Failed to get the answer")
return
}

XCTAssertEqual(decompressedData, answerData, "Decompression was incorrect")
}

}
Loading

0 comments on commit d0020a2

Please sign in to comment.