class PartiallyUncompressingPipe implements Closeable {

  public long pipe(InputStream in, Mode mode) throws IOException {
    long bytesWrittenBefore = out.getNumBytesWritten();
    if (mode == Mode.COPY) {
      int numRead = 0;
      while ((numRead = in.read(copyBuffer)) >= 0) {
        out.write(copyBuffer, 0, numRead);
      }
    } else {
      uncompressor.setNowrap(mode == Mode.UNCOMPRESS_NOWRAP);
      uncompressor.uncompress(in, out);
    }
    out.flush();
    return out.getNumBytesWritten() - bytesWrittenBefore;
  }

  public  PartiallyUncompressingPipe(OutputStream out, int copyBufferSize);

}