Skip to content

Commit b2c7a80

Browse files
committed
Swift 5.0 deprecation warnings suppressed
1 parent 7527bd3 commit b2c7a80

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

DataCompression.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "DataCompression"
3-
s.version = "3.3.0"
3+
s.version = "3.4.0"
44
s.summary = "Swift libcompression wrapper as an extension for the Data type (GZIP, ZLIB, LZFSE, LZMA, LZ4, deflate, RFC-1950, RFC-1951, RFC-1952)"
55
s.authors = { "Markus Wanke" => "mw99@users.noreply.github.com" }
66
s.homepage = "https://github.com/mw99/DataCompression"

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#### Swift version support
2222
| Library Version | Swift Version |
2323
|-----------------|---------------|
24-
| 3.2.0 -> 3.3.0 | 5.0 |
24+
| 3.4.0 | 5.0 |
2525
| 3.1.0 | 4.2 |
2626
| 3.0.0 | 3.0 -> 4.1 |
2727
| 2.0.1 | < 3.0 |
@@ -189,6 +189,10 @@ You only need one file located at `Sources/DataCompression.swift`. Drag and drop
189189

190190
## Change log / Upgrading guide
191191

192+
193+
##### Version `3.3.0` to `3.4.0`
194+
- Swift 5 release had further deprecation warnings than in the Swift 5 beta. Fixed.
195+
192196
##### Version `3.2.0` to `3.3.0`
193197
- Added support for Carthage
194198

Sources/DataCompression/DataCompression.swift

+11-4
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public extension Data
9595
/// - note: Fixed at compression level 5 (best trade off between speed and time)
9696
func zip() -> Data?
9797
{
98-
let header = Data(bytes: [0x78, 0x5e])
98+
let header = Data([0x78, 0x5e])
9999

100100
let deflated = self.withUnsafeBytes { (sourcePtr: UnsafePointer<UInt8>) -> Data? in
101101
let config = (operation: COMPRESSION_STREAM_ENCODE, algorithm: COMPRESSION_ZLIB)
@@ -153,7 +153,7 @@ public extension Data
153153
/// - note: Fixed at compression level 5 (best trade off between speed and time)
154154
func gzip() -> Data?
155155
{
156-
var header = Data(bytes: [0x1f, 0x8b, 0x08, 0x00]) // magic, magic, deflate, noflags
156+
var header = Data([0x1f, 0x8b, 0x08, 0x00]) // magic, magic, deflate, noflags
157157

158158
var unixtime = UInt32(Date().timeIntervalSince1970).littleEndian
159159
header.append(Data(bytes: &unixtime, count: MemoryLayout<UInt32>.size))
@@ -433,8 +433,15 @@ public struct Adler32: CustomStringConvertible
433433

434434

435435

436-
437-
436+
extension Data
437+
{
438+
func withUnsafeBytes<ResultType, ContentType>(_ body: (UnsafePointer<ContentType>) throws -> ResultType) rethrows -> ResultType
439+
{
440+
return try self.withUnsafeBytes({ (rawBufferPointer: UnsafeRawBufferPointer) -> ResultType in
441+
return try body(rawBufferPointer.bindMemory(to: ContentType.self).baseAddress!)
442+
})
443+
}
444+
}
438445

439446
fileprivate extension Data.CompressionAlgorithm
440447
{

Tests/DataCompressionTests/CompressionTest.swift

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ class CompressionTest: XCTestCase
99
{
1010
XCTAssertEqual("", pray(""))
1111
}
12+
13+
func testEmptyData()
14+
{
15+
XCTAssertEqual(Data(), comp(Data()))
16+
}
1217

1318
func testMiscSmall()
1419
{

0 commit comments

Comments
 (0)