      OutputStream
      InputStream
      PipedInputStream
-     PipedOutputStream]
+     PipedOutputStream
+     ByteArrayOutputStream]
     [java.security
      MessageDigest]
     [java.nio

  [x options]
  (InflaterInputStream. (bytes/to-input-stream x options)))

(defn- in->wrapped-out->in [^InputStream stream output-wrapper options]
  (let [chunk-size (get options :chunk-size 65536)
        out (PipedOutputStream.)
        in (PipedInputStream. out chunk-size)


    in))

(defn bytes->wrapped-out->bytes
  [bytes output-wrapper options]
  (if (or (instance? ByteBuffer bytes)
        (instance? byte-array bytes))
    (let [^ByteBuffer buf (bytes/to-byte-buffer bytes)
          out (ByteArrayOutputStream.)
          ^OutputStream compressor (output-wrapper out)
          ^bytes ary (clojure.core/byte-array 1024)]
      (loop []
        (let [remaining (.remaining buf)]
          (when (pos? remaining)
            (let [len (p/min remaining 1024)]
              (.get buf ary 0 len)
              (.write compressor ary 0 len)
              (recur)))))
      (.close compressor)
      (.close out)
      (.toByteArray out))
    (in->wrapped-out->in
      (bytes/to-input-stream bytes options)
      output-wrapper
      options)))

(def-compressor gzip
  [x options]
  (bytes->wrapped-out->bytes
    x
    #(GzipCompressorOutputStream. %)
    options))

