@@ -44,11 +44,11 @@ public enum FilterError: Error {
44
44
/// Filter failed to initialize,
45
45
/// invalid internal state,
46
46
/// invalid parameters
47
- case state
47
+ case invalidState
48
48
49
49
/// Invalid data in a call to compression_stream_process,
50
50
/// non-empty write after an output filter has been finalized
51
- case data
51
+ case invalidData
52
52
}
53
53
54
54
/// Compression filter direction of operation, compress/decompress
@@ -75,7 +75,7 @@ extension compression_stream {
75
75
/// - Parameter operation: direction of operation
76
76
/// - Parameter algorithm: compression algorithm
77
77
///
78
- /// - Throws: `FilterError.state ` if `algorithm` is not supported
78
+ /// - Throws: `FilterError.invalidState ` if `algorithm` is not supported
79
79
/// by the Compression stream API
80
80
///
81
81
internal init ( operation: FilterOperation , algorithm: Algorithm ) throws {
@@ -85,7 +85,7 @@ extension compression_stream {
85
85
src_size: 0 ,
86
86
state: nil )
87
87
let status = compression_stream_init ( & self , operation. rawValue, algorithm. rawValue)
88
- guard status == COMPRESSION_STATUS_OK else { throw FilterError . state }
88
+ guard status == COMPRESSION_STATUS_OK else { throw FilterError . invalidState }
89
89
}
90
90
}
91
91
@@ -105,7 +105,7 @@ public class OutputFilter {
105
105
/// - bufferCapacity: capacity of the internal data buffer
106
106
/// - writeFunc: called to write the processed data
107
107
///
108
- /// - Throws: `FilterError.state ` if stream initialization failed
108
+ /// - Throws: `FilterError.invalidState ` if stream initialization failed
109
109
public init (
110
110
_ operation: FilterOperation ,
111
111
using algorithm: Algorithm ,
@@ -127,14 +127,14 @@ public class OutputFilter {
127
127
/// - Parameter data: data to process
128
128
///
129
129
/// - Throws:
130
- /// `FilterError.data ` if an error occurs during processing,
130
+ /// `FilterError.invalidData ` if an error occurs during processing,
131
131
/// or if `data` is not empty/nil, and the filter is the finalized state
132
132
public func write< D : DataProtocol > ( _ data: D ? ) throws {
133
133
// Finalize if data is empty/nil
134
134
if data == nil || data!. isEmpty { try finalize ( ) ; return }
135
135
136
136
// Fail if already finalized
137
- if _finalized { throw FilterError . data }
137
+ if _finalized { throw FilterError . invalidData }
138
138
139
139
// Process all incoming data
140
140
for region in data!. regions {
@@ -152,7 +152,7 @@ public class OutputFilter {
152
152
/// When all output has been sent, the writingTo closure is called one last time with nil data.
153
153
/// Once the stream is finalized, writing non empty/nil data to the stream will throw an exception.
154
154
///
155
- /// - Throws: `FilterError.data ` if an error occurs during processing
155
+ /// - Throws: `FilterError.invalidData ` if an error occurs during processing
156
156
public func finalize( ) throws {
157
157
// Do nothing if already finalized
158
158
if _finalized { return }
@@ -187,7 +187,7 @@ public class OutputFilter {
187
187
_stream. dst_size = _bufCapacity
188
188
189
189
let status = compression_stream_process ( & _stream, ( finalize ? Int32 ( COMPRESSION_STREAM_FINALIZE . rawValue) : 0 ) )
190
- guard status != COMPRESSION_STATUS_ERROR else { throw FilterError . data }
190
+ guard status != COMPRESSION_STATUS_ERROR else { throw FilterError . invalidData }
191
191
192
192
// Number of bytes written to buf
193
193
let writtenBytes = _bufCapacity - _stream. dst_size
@@ -245,7 +245,7 @@ public class InputFilter<D: DataProtocol> {
245
245
public func advance( by n: Int ) throws {
246
246
247
247
// Sanity checks
248
- if n > _regionRemaining { throw FilterError . state } // invalid n
248
+ if n > _regionRemaining { throw FilterError . invalidState } // invalid n
249
249
250
250
// Update counters
251
251
_regionRemaining -= n
@@ -260,7 +260,7 @@ public class InputFilter<D: DataProtocol> {
260
260
}
261
261
262
262
// Sanity checks
263
- if _remaining != 0 && _regionRemaining == 0 { throw FilterError . state }
263
+ if _remaining != 0 && _regionRemaining == 0 { throw FilterError . invalidState }
264
264
}
265
265
}
266
266
@@ -279,7 +279,7 @@ public class InputFilter<D: DataProtocol> {
279
279
/// - bufferCapacity: capacity of the internal data buffer
280
280
/// - readFunc: called to read the input data
281
281
///
282
- /// - Throws: `FilterError.state ` if filter initialization failed
282
+ /// - Throws: `FilterError.invalidState ` if filter initialization failed
283
283
public init (
284
284
_ operation: FilterOperation ,
285
285
using algorithm: Algorithm ,
@@ -303,7 +303,7 @@ public class InputFilter<D: DataProtocol> {
303
303
/// - Returns: a new Data object containing at most `count` output bytes, or nil if no more data is available
304
304
///
305
305
/// - Throws:
306
- /// `FilterError.data ` if an error occurs during processing
306
+ /// `FilterError.invalidData ` if an error occurs during processing
307
307
public func readData( ofLength count: Int ) throws -> Data ? {
308
308
// Sanity check
309
309
precondition ( count > 0 , " number of bytes to read can't be 0 " )
@@ -340,7 +340,7 @@ public class InputFilter<D: DataProtocol> {
340
340
_stream. src_ptr = src_buf. baseAddress!. assumingMemoryBound ( to: UInt8 . self)
341
341
_stream. src_size = src_buf. count
342
342
let status = compression_stream_process ( & _stream, ( _eofReached ? Int32 ( COMPRESSION_STREAM_FINALIZE . rawValue) : 0 ) )
343
- guard status != COMPRESSION_STATUS_ERROR else { throw FilterError . data }
343
+ guard status != COMPRESSION_STATUS_ERROR else { throw FilterError . invalidData }
344
344
if status == COMPRESSION_STATUS_END { _endReached = true }
345
345
// Advance by the number of consumed bytes
346
346
let consumed = src_buf. count - _stream. src_size
@@ -349,7 +349,7 @@ public class InputFilter<D: DataProtocol> {
349
349
} else {
350
350
// No data available, process until END reached
351
351
let status = compression_stream_process ( & _stream, ( _eofReached ? Int32 ( COMPRESSION_STREAM_FINALIZE . rawValue) : 0 ) )
352
- guard status != COMPRESSION_STATUS_ERROR else { throw FilterError . data }
352
+ guard status != COMPRESSION_STATUS_ERROR else { throw FilterError . invalidData }
353
353
if status == COMPRESSION_STATUS_END { _endReached = true }
354
354
}
355
355
0 commit comments