mirror of
https://github.com/tsolomko/SWCompression.git
synced 2026-06-23 14:56:41 +00:00
Moved UInt8 and Data extensions to a combined file. Added function to "combine" two bytes into one.
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
061FCE2A1DBCC6070052F7BE /* test.txt in Resources */ = {isa = PBXBuildFile; fileRef = 061FCE281DBCC6070052F7BE /* test.txt */; };
|
||||
061FCE2B1DBCC6070052F7BE /* test.txt.gz in Resources */ = {isa = PBXBuildFile; fileRef = 061FCE291DBCC6070052F7BE /* test.txt.gz */; };
|
||||
061FCE2D1DBCC6A30052F7BE /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 061FCE2C1DBCC6A30052F7BE /* Constants.swift */; };
|
||||
061FCE311DBCC8BF0052F7BE /* DataExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 061FCE301DBCC8BF0052F7BE /* DataExtension.swift */; };
|
||||
061FCE311DBCC8BF0052F7BE /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 061FCE301DBCC8BF0052F7BE /* Extensions.swift */; };
|
||||
06BE1AD21DB410F100EE0F59 /* SWCompression.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 06BE1AC81DB410F100EE0F59 /* SWCompression.framework */; };
|
||||
06BE1AD71DB410F100EE0F59 /* SWCompressionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06BE1AD61DB410F100EE0F59 /* SWCompressionTests.swift */; };
|
||||
06BE1AD91DB410F100EE0F59 /* SWCompression.h in Headers */ = {isa = PBXBuildFile; fileRef = 06BE1ACB1DB410F100EE0F59 /* SWCompression.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
@@ -33,7 +33,7 @@
|
||||
061FCE281DBCC6070052F7BE /* test.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = test.txt; sourceTree = "<group>"; };
|
||||
061FCE291DBCC6070052F7BE /* test.txt.gz */ = {isa = PBXFileReference; lastKnownFileType = archive.gzip; path = test.txt.gz; sourceTree = "<group>"; };
|
||||
061FCE2C1DBCC6A30052F7BE /* Constants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
|
||||
061FCE301DBCC8BF0052F7BE /* DataExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataExtension.swift; sourceTree = "<group>"; };
|
||||
061FCE301DBCC8BF0052F7BE /* Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
|
||||
06BE1AC81DB410F100EE0F59 /* SWCompression.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SWCompression.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
06BE1ACB1DB410F100EE0F59 /* SWCompression.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SWCompression.h; sourceTree = "<group>"; };
|
||||
06BE1ACC1DB410F100EE0F59 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
@@ -93,7 +93,7 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
06BE1ACB1DB410F100EE0F59 /* SWCompression.h */,
|
||||
061FCE301DBCC8BF0052F7BE /* DataExtension.swift */,
|
||||
061FCE301DBCC8BF0052F7BE /* Extensions.swift */,
|
||||
061FCE251DBCC4BE0052F7BE /* Deflate.swift */,
|
||||
06E961C91DBD5FA1008C47F2 /* HuffmanTable.swift */,
|
||||
06BE1ACC1DB410F100EE0F59 /* Info.plist */,
|
||||
@@ -229,7 +229,7 @@
|
||||
files = (
|
||||
06E961CA1DBD5FA1008C47F2 /* HuffmanTable.swift in Sources */,
|
||||
061FCE261DBCC4BE0052F7BE /* Deflate.swift in Sources */,
|
||||
061FCE311DBCC8BF0052F7BE /* DataExtension.swift in Sources */,
|
||||
061FCE311DBCC8BF0052F7BE /* Extensions.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
@@ -8,23 +8,6 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
extension UInt8 {
|
||||
|
||||
subscript(index: Int) -> UInt8 {
|
||||
precondition(index >= 0 && index < 8, "Index must be between 0 and 7 (included)")
|
||||
let uindex = UInt8(truncatingBitPattern: index)
|
||||
return (self & (0x1 << uindex)) >> uindex
|
||||
}
|
||||
|
||||
subscript(range: CountableRange<Int>) -> [UInt8] {
|
||||
return range.map {
|
||||
let uindex = UInt8(truncatingBitPattern: $0)
|
||||
return (self & (0x1 << uindex)) >> uindex
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public enum DeflateError: Error {
|
||||
case WrongMagic
|
||||
case UnknownCompressionMethod
|
||||
|
||||
@@ -59,3 +59,24 @@ extension Data {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension UInt8 {
|
||||
|
||||
func combine(withByte second: UInt8) -> UInt16 {
|
||||
let result: UInt16 = UInt16(self << 8) | UInt16(second)
|
||||
return result
|
||||
}
|
||||
|
||||
subscript(index: Int) -> UInt8 {
|
||||
precondition(index >= 0 && index < 8, "Index must be between 0 and 7 (included).")
|
||||
let uindex = UInt8(truncatingBitPattern: index)
|
||||
return (self & (0x1 << uindex)) >> uindex
|
||||
}
|
||||
|
||||
subscript(range: CountableRange<Int>) -> [UInt8] {
|
||||
return range.map {
|
||||
let uindex = UInt8(truncatingBitPattern: $0)
|
||||
return (self & (0x1 << uindex)) >> uindex
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user