Back

compress (clj)

(source)

function

(compress input) (compress input {:keys [nowrap], :or {nowrap true}})
Given a plain byte array, compress it and return an other byte array.

Examples

funcool/buddy-core
(ns buddy.util.deflate-tests
  (:require [clojure.test :as t]
            [clojure.test.check.clojure-test :refer (defspec)]
            [clojure.test.check.generators :as gen]
            [clojure.test.check.properties :as props]
            [buddy.core.bytes :as bytes]
            [buddy.util.deflate :as df]))

(defspec deflate-compress-uncompress-spec 1000
  (props/for-all
   [data gen/bytes]
   (let [result1 (df/compress data)
         result2 (df/uncompress result1)]
     (t/is (bytes/equals? data result2)))))

(defspec deflate-compress-uncompress-zlib-spec 1000
         (props/for-all
           [data gen/bytes]
           (let [result1 (df/compress data {:nowrap false})
                 result2 (df/uncompress result1 {:nowrap false})]
             (t/is (bytes/equals? data result2)))))

(defspec deflate-compress-uncompress-zlib-fallback-spec 1000
         (props/for-all
           [data gen/bytes]
           (let [result1 (df/compress data {:nowrap false})
                 result2 (df/uncompress result1)]
             (t/is (bytes/equals? data result2)))))