 
    - Throws: `FilterError.StreamInitError` if stream initialization failed
    */
-  public init(_ operation: FilterOperation,
-              using algorithm : Algorithm,
-              bufferCapacity : Int = 65536,
-              writingTo writeFunc: @escaping (Data?) throws -> () ) throws
-  {
+  public init(
+    _ operation: FilterOperation,
+    using algorithm: Algorithm,
+    bufferCapacity: Int = 65536,
+    writingTo writeFunc: @escaping (Data?) throws -> ()
+  ) throws {
     _stream = try compression_stream(operation: operation, algorithm: algorithm)
     _buf = UnsafeMutablePointer<UInt8>.allocate(capacity: bufferCapacity)
     _bufCapacity = bufferCapacity


        // Refill _buf if needed, and EOF was not yet read
        if _stream.src_size == 0 && !_eofReached {
          try _buf = _readFunc(_bufCapacity) // may be nil
          // Reset src_size to full _buf size
          if _buf == nil || _buf!.count == 0 { _eofReached = true ; _stream.src_size = 0 }
          else { _stream.src_size = _buf!.count }
        }

        // Process some data
        if _buf != nil {

          let bufCount = _buf!.count
          try _buf!.withUnsafeBytes { (src_ptr: UnsafePointer<UInt8>) in

            // Next byte to read
            _stream.src_ptr = src_ptr.advanced(by: bufCount - _stream.src_size)

            let status = compression_stream_process(&_stream, (_eofReached ? Int32(COMPRESSION_STREAM_FINALIZE.rawValue) : 0))
            guard status != COMPRESSION_STATUS_ERROR else { throw FilterError.FilterProcessError }
            if status == COMPRESSION_STATUS_END { _endReached = true }
          }

        } else {

          let status = compression_stream_process(&_stream, (_eofReached ? Int32(COMPRESSION_STREAM_FINALIZE.rawValue) : 0))
          guard status != COMPRESSION_STATUS_ERROR else { throw FilterError.FilterProcessError }
          if status == COMPRESSION_STATUS_END { _endReached = true }

        }

  }

  // Cleanup resources
  deinit {
    compression_stream_destroy(&_stream)
  }

