Skip to content

Commit 781a9e3

Browse files
committed
Update starscream for new dep; add spm build
1 parent f00af67 commit 781a9e3

File tree

3 files changed

+31
-29
lines changed

3 files changed

+31
-29
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ before_install:
1212
script:
1313
- xcodebuild -project Socket.IO-Client-Swift.xcodeproj -scheme SocketIO-Mac build-for-testing -quiet
1414
- xctool -project Socket.IO-Client-Swift.xcodeproj -scheme SocketIO-Mac run-tests --parallelize
15+
- swift build
1516
#script: xcodebuild -project Socket.IO-Client-Swift.xcodeproj -scheme SocketIO-Mac build test

Source/Compression.swift

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@
2525
//
2626
//////////////////////////////////////////////////////////////////////////////////////////////////
2727
import Foundation
28-
import zlib
28+
import CZLib
2929

3030
class Decompressor {
3131
private var strm = z_stream()
3232
private var buffer = [UInt8](repeating: 0, count: 0x2000)
3333
private var inflateInitialized = false
3434
private let windowBits:Int
35-
35+
3636
init?(windowBits:Int) {
3737
self.windowBits = windowBits
3838
guard initInflate() else { return nil }
3939
}
40-
40+
4141
private func initInflate() -> Bool {
4242
if Z_OK == inflateInit2_(&strm, -CInt(windowBits),
4343
ZLIB_VERSION, CInt(MemoryLayout<z_stream>.size))
@@ -47,59 +47,59 @@ class Decompressor {
4747
}
4848
return false
4949
}
50-
50+
5151
func reset() throws {
5252
teardownInflate()
5353
guard initInflate() else { throw NSError() }
5454
}
55-
55+
5656
func decompress(_ data: Data, finish: Bool) throws -> Data {
5757
return try data.withUnsafeBytes { (bytes:UnsafePointer<UInt8>) -> Data in
5858
return try decompress(bytes: bytes, count: data.count, finish: finish)
5959
}
6060
}
61-
61+
6262
func decompress(bytes: UnsafePointer<UInt8>, count: Int, finish: Bool) throws -> Data {
6363
var decompressed = Data()
6464
try decompress(bytes: bytes, count: count, out: &decompressed)
65-
65+
6666
if finish {
6767
let tail:[UInt8] = [0x00, 0x00, 0xFF, 0xFF]
6868
try decompress(bytes: tail, count: tail.count, out: &decompressed)
6969
}
70-
70+
7171
return decompressed
72-
72+
7373
}
74-
74+
7575
private func decompress(bytes: UnsafePointer<UInt8>, count: Int, out:inout Data) throws {
7676
var res:CInt = 0
7777
strm.next_in = UnsafeMutablePointer<UInt8>(mutating: bytes)
7878
strm.avail_in = CUnsignedInt(count)
79-
79+
8080
repeat {
8181
strm.next_out = UnsafeMutablePointer<UInt8>(&buffer)
8282
strm.avail_out = CUnsignedInt(buffer.count)
83-
83+
8484
res = inflate(&strm, 0)
85-
85+
8686
let byteCount = buffer.count - Int(strm.avail_out)
8787
out.append(buffer, count: byteCount)
8888
} while res == Z_OK && strm.avail_out == 0
89-
89+
9090
guard (res == Z_OK && strm.avail_out > 0)
9191
|| (res == Z_BUF_ERROR && Int(strm.avail_out) == buffer.count)
9292
else {
9393
throw NSError(domain: WebSocket.ErrorDomain, code: Int(WebSocket.InternalErrorCode.compressionError.rawValue), userInfo: nil)
9494
}
9595
}
96-
96+
9797
private func teardownInflate() {
9898
if inflateInitialized, Z_OK == inflateEnd(&strm) {
9999
inflateInitialized = false
100100
}
101101
}
102-
102+
103103
deinit {
104104
teardownInflate()
105105
}
@@ -110,12 +110,12 @@ class Compressor {
110110
private var buffer = [UInt8](repeating: 0, count: 0x2000)
111111
private var deflateInitialized = false
112112
private let windowBits:Int
113-
113+
114114
init?(windowBits: Int) {
115115
self.windowBits = windowBits
116116
guard initDeflate() else { return nil }
117117
}
118-
118+
119119
private func initDeflate() -> Bool {
120120
if Z_OK == deflateInit2_(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
121121
-CInt(windowBits), 8, Z_DEFAULT_STRATEGY,
@@ -126,48 +126,48 @@ class Compressor {
126126
}
127127
return false
128128
}
129-
129+
130130
func reset() throws {
131131
teardownDeflate()
132132
guard initDeflate() else { throw NSError() }
133133
}
134-
134+
135135
func compress(_ data: Data) throws -> Data {
136136
var compressed = Data()
137137
var res:CInt = 0
138138
data.withUnsafeBytes { (ptr:UnsafePointer<UInt8>) -> Void in
139139
strm.next_in = UnsafeMutablePointer<UInt8>(mutating: ptr)
140140
strm.avail_in = CUnsignedInt(data.count)
141-
141+
142142
repeat {
143143
strm.next_out = UnsafeMutablePointer<UInt8>(&buffer)
144144
strm.avail_out = CUnsignedInt(buffer.count)
145-
145+
146146
res = deflate(&strm, Z_SYNC_FLUSH)
147-
147+
148148
let byteCount = buffer.count - Int(strm.avail_out)
149149
compressed.append(buffer, count: byteCount)
150150
}
151151
while res == Z_OK && strm.avail_out == 0
152-
152+
153153
}
154-
154+
155155
guard res == Z_OK && strm.avail_out > 0
156156
|| (res == Z_BUF_ERROR && Int(strm.avail_out) == buffer.count)
157157
else {
158158
throw NSError(domain: WebSocket.ErrorDomain, code: Int(WebSocket.InternalErrorCode.compressionError.rawValue), userInfo: nil)
159159
}
160-
160+
161161
compressed.removeLast(4)
162162
return compressed
163163
}
164-
164+
165165
private func teardownDeflate() {
166166
if deflateInitialized, Z_OK == deflateEnd(&strm) {
167167
deflateInitialized = false
168168
}
169169
}
170-
170+
171171
deinit {
172172
teardownDeflate()
173173
}

zlib/module.modulemap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
module zlib [system] {
1+
module CZLib [system] {
22
header "include.h"
33
link "z"
4+
export *
45
}
56
module CommonCrypto [system] {
67
header "include.h"

0 commit comments

Comments
 (0)