Skip to content

Commit

Permalink
Swift 5.0 deprecation warnings suppressed
Browse files Browse the repository at this point in the history
  • Loading branch information
mw99 committed Mar 27, 2019
1 parent 7527bd3 commit b2c7a80
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DataCompression.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "DataCompression"
s.version = "3.3.0"
s.version = "3.4.0"
s.summary = "Swift libcompression wrapper as an extension for the Data type (GZIP, ZLIB, LZFSE, LZMA, LZ4, deflate, RFC-1950, RFC-1951, RFC-1952)"
s.authors = { "Markus Wanke" => "[email protected]" }
s.homepage = "https://github.com/mw99/DataCompression"
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#### Swift version support
| Library Version | Swift Version |
|-----------------|---------------|
| 3.2.0 -> 3.3.0 | 5.0 |
| 3.4.0 | 5.0 |
| 3.1.0 | 4.2 |
| 3.0.0 | 3.0 -> 4.1 |
| 2.0.1 | < 3.0 |
Expand Down Expand Up @@ -189,6 +189,10 @@ You only need one file located at `Sources/DataCompression.swift`. Drag and drop

## Change log / Upgrading guide


##### Version `3.3.0` to `3.4.0`
- Swift 5 release had further deprecation warnings than in the Swift 5 beta. Fixed.

##### Version `3.2.0` to `3.3.0`
- Added support for Carthage

Expand Down
15 changes: 11 additions & 4 deletions Sources/DataCompression/DataCompression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public extension Data
/// - note: Fixed at compression level 5 (best trade off between speed and time)
func zip() -> Data?
{
let header = Data(bytes: [0x78, 0x5e])
let header = Data([0x78, 0x5e])

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

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





extension Data
{
func withUnsafeBytes<ResultType, ContentType>(_ body: (UnsafePointer<ContentType>) throws -> ResultType) rethrows -> ResultType
{
return try self.withUnsafeBytes({ (rawBufferPointer: UnsafeRawBufferPointer) -> ResultType in
return try body(rawBufferPointer.bindMemory(to: ContentType.self).baseAddress!)
})
}
}

fileprivate extension Data.CompressionAlgorithm
{
Expand Down
5 changes: 5 additions & 0 deletions Tests/DataCompressionTests/CompressionTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ class CompressionTest: XCTestCase
{
XCTAssertEqual("", pray(""))
}

func testEmptyData()
{
XCTAssertEqual(Data(), comp(Data()))
}

func testMiscSmall()
{
Expand Down

0 comments on commit b2c7a80

Please sign in to comment.