-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
220 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,3 +63,4 @@ fastlane/report.xml | |
fastlane/Preview.html | ||
fastlane/screenshots | ||
fastlane/test_output | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,29 @@ | ||
branches: | ||
- develop | ||
- master | ||
|
||
osx_image: xcode8 | ||
- develop | ||
- master | ||
language: objective-c | ||
osx_image: xcode8 | ||
xcode_project: SWCompression.xcodeproj | ||
xcode_scheme: SWCompression | ||
env: | ||
global: | ||
- FRAMEWORK_NAME=SWCompression | ||
before_install: | ||
- brew update | ||
- brew outdated carthage || brew upgrade carthage | ||
before_deploy: | ||
- carthage build --no-skip-current | ||
- carthage archive $FRAMEWORK_NAME | ||
script: | ||
- xcodebuild clean build test -project SWCompression.xcodeproj -scheme SWCompression | ||
notifications: | ||
email: false | ||
deploy: | ||
provider: releases | ||
api_key: | ||
secure: lhJi7BsAuhGo9T4rgD/UWlVRnfrO5xLIF3BUuPHb21045tEXk/BGEHgc9a9CTFm2/iR3SmP/GDsmqfJlMzWLvuTlyV5i8otIodwIp5NYstFhyA2JaEVglmnzlkf/2FkNb5KKJDyGM1KuecYmPRTUUzYThVXl59GZ2esgfiCN26pDeDgwRyJt34jeUj0VzK9JDmEJ/ODG/hvuUWyZp0zni+m6WTPZ7dILeazFEc81WATBfMo5oa8ZBChSM6lDKaW8XyKZWrMXjsK6dKfQTcVwnvrplfw2TqfPVA+YfePcq1os5Do5CELnhrUZMSI6qvOmPauzGStjsAVFTiMaYO6HdHO03mn5L9SUuyhhKqHmh2pAkM1zKxbtfKbk6oi4zJJgvbTjIO4K2X5SUwHFgjULijW9JJeCFjsLfwODvFNFHeLeql3jaKNo6kRn2VvT/uNuT3aZa+r+WeFL0HgD6Z/EEkQW5yI6DocjetRP6y9B0rpA+YyALbd0SkVIqvoywztSfxWwp7eKhQHbG/FTIfWlmMbtLq5xULQb6TyjVHO94iSfsDV2rjAeDJY73P+rPsvej4Y9LFS8VOHcsrFhFlbR9E0NjCO2CH2TZcjXPOdLu4gfapPdiqQIdgWjC6ECUwsq+Ux6jJ6QIrGC2TI/Fw58mtLf1G8SdqBRXo+Kw0IAB4g= | ||
file: "$FRAMEWORK_NAME.framework.zip" | ||
skip_cleanup: true | ||
on: | ||
repo: tsolomko/SWCompression | ||
tags: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// | ||
// DataWithPointer.swift | ||
// SWCompression | ||
// | ||
// Created by Timofey Solomko on 01.11.16. | ||
// Copyright © 2016 Timofey Solomko. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import CoreFoundation | ||
|
||
class DataWithPointer { | ||
|
||
/// Only needed for creation of bitVector in initData() | ||
let data: Data | ||
|
||
private(set) var bitVector: CFBitVector? | ||
private(set) var index: Int | ||
private(set) var bitShift: Int | ||
|
||
init(data: Data) { | ||
self.data = data | ||
self.index = 0 | ||
self.bitShift = 0 | ||
self.bitVector = nil | ||
data.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) in | ||
self.bitVector = CFBitVectorCreate(kCFAllocatorDefault, bytes, data.count * 8) | ||
} | ||
} | ||
|
||
func bits(count: Int) -> [UInt8] { | ||
guard count > 0 else { return [] } | ||
|
||
var array: [UInt8] = [] | ||
for _ in 0..<count { | ||
let currentIndex = 8 * (index + 1) - bitShift - 1 | ||
array.append(UInt8(truncatingBitPattern: CFBitVectorGetBitAtIndex(self.bitVector!, currentIndex))) | ||
self.bitShift += 1 | ||
if self.bitShift >= 8 { | ||
self.bitShift = 0 | ||
self.index += 1 | ||
} | ||
} | ||
|
||
return array | ||
} | ||
|
||
func bit() -> UInt8 { | ||
return self.bits(count: 1).first! | ||
} | ||
|
||
/// Use with caution: not effective. | ||
func data(ofBytes count: Data.Index) -> Data { | ||
precondition(self.bitShift == 0, "Misaligned byte.") | ||
let returnData = Data(data[index..<index+count]) | ||
index += count | ||
return returnData | ||
} | ||
|
||
// MARK: Manipulation with index and bitShift | ||
|
||
func skipUntilNextByte() { | ||
self.index += 1 | ||
self.bitShift = 0 | ||
} | ||
|
||
func rewind(bitsCount: Int) { | ||
let amountOfBytes = (bitsCount - self.bitShift) / 8 + 1 | ||
self.index -= amountOfBytes | ||
self.bitShift = 8 - (bitsCount - self.bitShift) % 8 | ||
|
||
if self.bitShift == 8 { | ||
self.index += 1 | ||
self.bitShift = 0 | ||
} | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.