       }
 
       // Sanity checks
-      if _remaining != 0 && _regionRemaining == 0 { throw FilterError.state }
+      if _remaining != 0 && _regionRemaining == 0 { throw FilterError.invalidState }
     }
   }
 

        } else {
          // No data available, process until END reached
          let status = compression_stream_process(&_stream, (_eofReached ? Int32(COMPRESSION_STREAM_FINALIZE.rawValue) : 0))
          guard status != COMPRESSION_STATUS_ERROR else { throw FilterError.data }
          if status == COMPRESSION_STATUS_END { _endReached = true }
        }


  /// When all output has been sent, the writingTo closure is called one last time with nil data.
  /// Once the stream is finalized, writing non empty/nil data to the stream will throw an exception.
  ///
  /// - Throws: `FilterError.invalidData` if an error occurs during processing
  public func finalize() throws {
    // Do nothing if already finalized
    if _finalized { return }
