mirror of
https://github.com/tsolomko/SWCompression.git
synced 2026-06-23 14:56:41 +00:00
Added useful UInt8 extensions.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
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, ); }; };
|
||||
06E961CA1DBD5FA1008C47F2 /* HuffmanTable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06E961C91DBD5FA1008C47F2 /* HuffmanTable.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
@@ -39,6 +40,7 @@
|
||||
06BE1AD11DB410F100EE0F59 /* SWCompressionTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SWCompressionTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
06BE1AD61DB410F100EE0F59 /* SWCompressionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SWCompressionTests.swift; sourceTree = "<group>"; };
|
||||
06BE1AD81DB410F100EE0F59 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
06E961C91DBD5FA1008C47F2 /* HuffmanTable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HuffmanTable.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@@ -93,6 +95,7 @@
|
||||
06BE1ACB1DB410F100EE0F59 /* SWCompression.h */,
|
||||
061FCE301DBCC8BF0052F7BE /* DataExtension.swift */,
|
||||
061FCE251DBCC4BE0052F7BE /* Deflate.swift */,
|
||||
06E961C91DBD5FA1008C47F2 /* HuffmanTable.swift */,
|
||||
06BE1ACC1DB410F100EE0F59 /* Info.plist */,
|
||||
);
|
||||
path = Sources;
|
||||
@@ -224,6 +227,7 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
06E961CA1DBD5FA1008C47F2 /* HuffmanTable.swift in Sources */,
|
||||
061FCE261DBCC4BE0052F7BE /* Deflate.swift in Sources */,
|
||||
061FCE311DBCC8BF0052F7BE /* DataExtension.swift in Sources */,
|
||||
);
|
||||
|
||||
@@ -8,6 +8,24 @@
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user