@@ -14,9 +14,7 @@ import Darwin
14
14
import Foundation
15
15
@_exported import Compression
16
16
17
- /**
18
- Compression algorithms, wraps the C API constants.
19
- */
17
+ /// Compression algorithms, wraps the C API constants.
20
18
public enum Algorithm : CaseIterable {
21
19
22
20
/// LZFSE
@@ -41,9 +39,7 @@ public enum Algorithm: CaseIterable {
41
39
}
42
40
}
43
41
44
- /**
45
- Compression errors
46
- */
42
+ /// Compression errors
47
43
public enum FilterError : Error {
48
44
/// Filter failed to initialize
49
45
case filterInitError
@@ -55,9 +51,7 @@ public enum FilterError: Error {
55
51
case writeToFinalizedFilter
56
52
}
57
53
58
- /**
59
- Compression filter direction of operation, compress/decompress
60
- */
54
+ /// Compression filter direction of operation, compress/decompress
61
55
public enum FilterOperation {
62
56
/// Compress raw data to a compressed payload
63
57
case compress
@@ -76,15 +70,15 @@ public enum FilterOperation {
76
70
@available ( macOS 10 . 12 , iOS 10 . 0 , watchOS 3 . 0 , tvOS 10 . 0 , * )
77
71
extension compression_stream {
78
72
79
- /**
80
- Initialize a compression_stream struct
81
-
82
- - Parameter operation: direction of operation
83
- - Parameter algorithm: compression algorithm
84
-
85
- - Throws: `FilterError.filterInitError` if `algorithm` is not supported by the Compression stream API
86
- * /
87
- init ( operation: FilterOperation , algorithm: Algorithm ) throws {
73
+ /// Initialize a compression_stream struct
74
+ ///
75
+ /// - Parameter operation: direction of operation
76
+ /// - Parameter algorithm: compression algorithm
77
+ ///
78
+ /// - Throws: `FilterError.filterInitError` if `algorithm` is not supported
79
+ /// by the Compression stream API
80
+ // /
81
+ internal init ( operation: FilterOperation , algorithm: Algorithm ) throws {
88
82
self . init ( dst_ptr: UnsafeMutablePointer< UInt8> . allocate( capacity: 0 ) ,
89
83
dst_size: 0 ,
90
84
src_ptr: UnsafeMutablePointer< UInt8> . allocate( capacity: 0 ) ,
@@ -93,7 +87,6 @@ extension compression_stream {
93
87
let status = compression_stream_init ( & self , operation. rawValue, algorithm. rawValue)
94
88
guard status == COMPRESSION_STATUS_OK else { throw FilterError . filterInitError }
95
89
}
96
-
97
90
}
98
91
99
92
@available ( macOS 10 . 12 , iOS 10 . 0 , watchOS 3 . 0 , tvOS 10 . 0 , * )
@@ -104,17 +97,15 @@ public class OutputFilter {
104
97
private let _writeFunc : ( Data ? ) throws -> ( )
105
98
private var _finalized : Bool = false
106
99
107
- /**
108
- Initialize an output filter
109
-
110
- - Parameters:
111
- - operation: direction of operation
112
- - algorithm: compression algorithm
113
- - bufferCapacity: capacity of the internal data buffer
114
- - writeFunc: called to write the processed data
115
-
116
- - Throws: `FilterError.StreamInitError` if stream initialization failed
117
- */
100
+ /// Initialize an output filter
101
+ ///
102
+ /// - Parameters:
103
+ /// - operation: direction of operation
104
+ /// - algorithm: compression algorithm
105
+ /// - bufferCapacity: capacity of the internal data buffer
106
+ /// - writeFunc: called to write the processed data
107
+ ///
108
+ /// - Throws: `FilterError.StreamInitError` if stream initialization failed
118
109
public init (
119
110
_ operation: FilterOperation ,
120
111
using algorithm: Algorithm ,
@@ -127,19 +118,18 @@ public class OutputFilter {
127
118
_writeFunc = writeFunc
128
119
}
129
120
130
- /**
131
- Send data to output filter
132
-
133
- Processed output will be sent to the output closure.
134
- A call with empty/nil data is interpreted as finalize().
135
- Writing non empty/nil data to a finalized stream is an error.
136
-
137
- - Parameter data: data to process
138
-
139
- - Throws:
140
- `FilterError.filterProcessError` if an error occurs during processing
141
- `FilterError.writeToFinalizedFilter` if `data` is not empty/nil, and the filter is the finalized state
142
- */
121
+ /// Send data to output filter
122
+ ///
123
+ /// Processed output will be sent to the output closure.
124
+ /// A call with empty/nil data is interpreted as finalize().
125
+ /// Writing non empty/nil data to a finalized stream is an error.
126
+ ///
127
+ /// - Parameter data: data to process
128
+ ///
129
+ /// - Throws:
130
+ /// `FilterError.filterProcessError` if an error occurs during processing
131
+ /// `FilterError.writeToFinalizedFilter` if `data` is not empty/nil, and the
132
+ /// filter is the finalized state
143
133
public func write( _ data: Data ? ) throws {
144
134
// Finalize if data is empty/nil
145
135
if data == nil || data!. isEmpty { try finalize ( ) ; return }
@@ -155,15 +145,13 @@ public class OutputFilter {
155
145
}
156
146
}
157
147
158
- /**
159
- Finalize the stream, i.e. flush all data remaining in the stream
160
-
161
- Processed output will be sent to the output closure.
162
- When all output has been sent, the writingTo closure is called one last time with nil data.
163
- Once the stream is finalized, writing non empty/nil data to the stream will throw an exception.
164
-
165
- - Throws: `FilterError.StreamProcessError` if an error occurs during processing
166
- */
148
+ /// Finalize the stream, i.e. flush all data remaining in the stream
149
+ ///
150
+ /// Processed output will be sent to the output closure.
151
+ /// When all output has been sent, the writingTo closure is called one last time with nil data.
152
+ /// Once the stream is finalized, writing non empty/nil data to the stream will throw an exception.
153
+ ///
154
+ /// - Throws: `FilterError.StreamProcessError` if an error occurs during processing
167
155
public func finalize( ) throws {
168
156
// Do nothing if already finalized
169
157
if _finalized { return }
@@ -223,17 +211,15 @@ public class InputFilter {
223
211
private var _eofReached : Bool = false // did we read end-of-file from the input?
224
212
private var _endReached : Bool = false // did we reach end-of-file from the decoder stream?
225
213
226
- /**
227
- Initialize an input filter
228
-
229
- - Parameters:
230
- - operation: direction of operation
231
- - algorithm: compression algorithm
232
- - bufferCapacity: capacity of the internal data buffer
233
- - readFunc: called to read the input data
234
-
235
- - Throws: `FilterError.filterInitError` if filter initialization failed
236
- */
214
+ /// Initialize an input filter
215
+ ///
216
+ /// - Parameters:
217
+ /// - operation: direction of operation
218
+ /// - algorithm: compression algorithm
219
+ /// - bufferCapacity: capacity of the internal data buffer
220
+ /// - readFunc: called to read the input data
221
+ ///
222
+ /// - Throws: `FilterError.filterInitError` if filter initialization failed
237
223
public init (
238
224
_ operation: FilterOperation ,
239
225
using algorithm: Algorithm ,
@@ -245,21 +231,19 @@ public class InputFilter {
245
231
_readFunc = readFunc
246
232
}
247
233
248
- /**
249
- Read processed data from the filter
250
-
251
- Input data, when needed, is obtained from the input closure
252
- When the input closure returns a nil or empty Data object, the filter will be
253
- finalized, and after all processed data has been read, readData will return nil
254
- to signal end of input
255
-
256
- - Parameter count: max number of bytes to read from the filter
257
-
258
- - Returns: a new Data object containing at most `count` output bytes, or nil if no more data is available
259
-
260
- - Throws:
261
- `FilterError.filterProcessError` if an error occurs during processing
262
- */
234
+ /// Read processed data from the filter
235
+ ///
236
+ /// Input data, when needed, is obtained from the input closure
237
+ /// When the input closure returns a nil or empty Data object, the filter will be
238
+ /// finalized, and after all processed data has been read, readData will return nil
239
+ /// to signal end of input
240
+ ///
241
+ /// - Parameter count: max number of bytes to read from the filter
242
+ ///
243
+ /// - Returns: a new Data object containing at most `count` output bytes, or nil if no more data is available
244
+ ///
245
+ /// - Throws:
246
+ /// `FilterError.filterProcessError` if an error occurs during processing
263
247
public func readData( ofLength count: Int ) throws -> Data ? {
264
248
// Sanity check
265
249
precondition ( count > 0 , " number of bytes to read can't be 0 " )
0 commit comments