From 6641427c853524136e1d7cb3e32de839416badf1 Mon Sep 17 00:00:00 2001 From: victorbjelkholm Date: Wed, 27 Oct 2021 11:08:56 +0200 Subject: [PATCH 01/10] Add setting the zlib level when inflating License: Apache License 2.0 Signed-off-by: Victor Bjelkholm --- src-clj/zlib_tiny/core.clj | 13 +++++++++---- test/zlib_tiny/compress.clj | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src-clj/zlib_tiny/core.clj b/src-clj/zlib_tiny/core.clj index 080f019..56ea561 100644 --- a/src-clj/zlib_tiny/core.clj +++ b/src-clj/zlib_tiny/core.clj @@ -1,9 +1,10 @@ (ns zlib-tiny.core (:import (java.util.zip InflaterInputStream + Inflater GZIPInputStream GZIPOutputStream DeflaterInputStream - Inflater + Deflater ZipException CRC32) (zlib_tiny CRC64) @@ -75,9 +76,13 @@ (defn deflate "Returns a deflate'd version of the given byte array." - [b] - (when b - (IOUtils/toByteArray (DeflaterInputStream. (ByteArrayInputStream. b))))) + ([b] + (when b + (IOUtils/toByteArray (DeflaterInputStream. (ByteArrayInputStream. b))))) + ([b level] + (let [deflater (Deflater. level)] + (IOUtils/toByteArray (DeflaterInputStream. (ByteArrayInputStream. b) + deflater))))) (comment "ZLib Example" (bytes->str (force-byte-array (inflate (deflate (str->bytes "test it!")))))) diff --git a/test/zlib_tiny/compress.clj b/test/zlib_tiny/compress.clj index 1e587ce..5dff509 100644 --- a/test/zlib_tiny/compress.clj +++ b/test/zlib_tiny/compress.clj @@ -4,6 +4,17 @@ (def test-string "test it!") +(defn t-inflate #^bytes [string-to-compress compression-level] + (-> string-to-compress + (str->bytes) + (deflate (or compression-level -1)))) + +(defn t-deflate [b] + (-> b + inflate + force-byte-array + bytes->str)) + (deftest compressors (testing "Checking ZLib" (is (= test-string (-> test-string @@ -13,6 +24,15 @@ force-byte-array bytes->str)))) + (testing "Setting compression level" + (let [with-highest-level (t-inflate test-string 9) + with-lower-level (t-inflate test-string 0)] + (is (> (alength with-lower-level) + (alength with-highest-level)) + "'with-lower-level wasn't smaller than 'with-highest-level") + (is (= (t-deflate with-lower-level) + (t-deflate with-highest-level))))) + (testing "Checking GZip" (is (= test-string (-> test-string str->bytes From ef015a260ed9f32635ad5e5b775ef278849e38d2 Mon Sep 17 00:00:00 2001 From: victorbjelkholm Date: Wed, 27 Oct 2021 12:13:05 +0200 Subject: [PATCH 02/10] Call .end on deflater when we're done Otherwise it'll hold on to the data and might leak memory if GC is not called fast enough. See https://docs.oracle.com/javase/7/docs/api/java/util/zip/Deflater.html#end() License: Apache License 2.0 Signed-off-by: Victor Bjelkholm --- src-clj/zlib_tiny/core.clj | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src-clj/zlib_tiny/core.clj b/src-clj/zlib_tiny/core.clj index 56ea561..33a6f41 100644 --- a/src-clj/zlib_tiny/core.clj +++ b/src-clj/zlib_tiny/core.clj @@ -80,9 +80,11 @@ (when b (IOUtils/toByteArray (DeflaterInputStream. (ByteArrayInputStream. b))))) ([b level] - (let [deflater (Deflater. level)] - (IOUtils/toByteArray (DeflaterInputStream. (ByteArrayInputStream. b) - deflater))))) + (let [deflater (Deflater. level) + ba (IOUtils/toByteArray (DeflaterInputStream. (ByteArrayInputStream. b) + deflater))] + (.end deflater) + ba))) (comment "ZLib Example" (bytes->str (force-byte-array (inflate (deflate (str->bytes "test it!")))))) From 287ece20ac4c5de136946883f723cd0d274cfbb5 Mon Sep 17 00:00:00 2001 From: source-c Date: Thu, 28 Oct 2021 12:46:19 +0300 Subject: [PATCH 03/10] Create clojure.yml --- .github/workflows/clojure.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .github/workflows/clojure.yml diff --git a/.github/workflows/clojure.yml b/.github/workflows/clojure.yml new file mode 100644 index 0000000..22bfe20 --- /dev/null +++ b/.github/workflows/clojure.yml @@ -0,0 +1,19 @@ +name: Clojure CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Install dependencies + run: lein deps + - name: Run tests + run: lein test From a14b199298784e1af66d2e9907aa41cab6403b15 Mon Sep 17 00:00:00 2001 From: source-c Date: Thu, 28 Oct 2021 12:47:41 +0300 Subject: [PATCH 04/10] Update clojure.yml --- .github/workflows/clojure.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/clojure.yml b/.github/workflows/clojure.yml index 22bfe20..64d450e 100644 --- a/.github/workflows/clojure.yml +++ b/.github/workflows/clojure.yml @@ -1,10 +1,10 @@ -name: Clojure CI +name: Clojure CI for trunk on: push: - branches: [ master ] + branches: [ trunk ] pull_request: - branches: [ master ] + branches: [ trunk ] jobs: build: From c306e79ec82826e0dd5de06ce1dc137121518a3d Mon Sep 17 00:00:00 2001 From: MelKori Date: Thu, 28 Oct 2021 13:17:23 +0300 Subject: [PATCH 05/10] sync names with Standard Algorithm Name Documentation by Oracle --- src-clj/zlib_tiny/core.clj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src-clj/zlib_tiny/core.clj b/src-clj/zlib_tiny/core.clj index 080f019..5fbe664 100644 --- a/src-clj/zlib_tiny/core.clj +++ b/src-clj/zlib_tiny/core.clj @@ -104,17 +104,17 @@ (defn md5 ^bytes [^bytes b] - (wrap-digest "md5" b)) + (wrap-digest "MD5" b)) (defn sha-1 ^bytes [^bytes b] - (wrap-digest "sha1" b)) + (wrap-digest "SHA-1" b)) (defn sha-256 ^bytes [^bytes b] - (wrap-digest "sha256" b)) + (wrap-digest "SHA-256" b)) (defn sha-512 ^bytes [^bytes b] - (wrap-digest "sha-512" b)) + (wrap-digest "SHA-512" b)) From 8194c09801a9a3db662a60ee456faf25b47c1100 Mon Sep 17 00:00:00 2001 From: source-c Date: Thu, 28 Oct 2021 12:46:19 +0300 Subject: [PATCH 06/10] Create clojure.yml --- .github/workflows/clojure.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .github/workflows/clojure.yml diff --git a/.github/workflows/clojure.yml b/.github/workflows/clojure.yml new file mode 100644 index 0000000..22bfe20 --- /dev/null +++ b/.github/workflows/clojure.yml @@ -0,0 +1,19 @@ +name: Clojure CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Install dependencies + run: lein deps + - name: Run tests + run: lein test From 53c628cd7ac6703041a5c8187b6357f7036997e8 Mon Sep 17 00:00:00 2001 From: source-c Date: Thu, 28 Oct 2021 12:47:41 +0300 Subject: [PATCH 07/10] Update clojure.yml --- .github/workflows/clojure.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/clojure.yml b/.github/workflows/clojure.yml index 22bfe20..64d450e 100644 --- a/.github/workflows/clojure.yml +++ b/.github/workflows/clojure.yml @@ -1,10 +1,10 @@ -name: Clojure CI +name: Clojure CI for trunk on: push: - branches: [ master ] + branches: [ trunk ] pull_request: - branches: [ master ] + branches: [ trunk ] jobs: build: From 83bd14880328b79b258be30fe84dcd20ee5805c1 Mon Sep 17 00:00:00 2001 From: MelKori Date: Thu, 28 Oct 2021 13:24:35 +0300 Subject: [PATCH 08/10] bump version --- project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.clj b/project.clj index 0c99f53..7fe540f 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject net.tbt-post/zlib-tiny "0.4.0" +(defproject net.tbt-post/zlib-tiny "0.4.1" :description "Tiny Clojure ZLib helper" :url "https://github.com/source-c/zlib-tiny" :license {:name "Apache License v2.0" From eb5d103ef96ff7e86ae98c46eef4f5e06df0ee97 Mon Sep 17 00:00:00 2001 From: MelKori Date: Thu, 28 Oct 2021 15:00:05 +0300 Subject: [PATCH 09/10] split CI configs to trunk and master --- .github/workflows/clojure-master.yml | 19 +++++++++++++++++++ .../{clojure.yml => clojure-trunk.yml} | 0 2 files changed, 19 insertions(+) create mode 100644 .github/workflows/clojure-master.yml rename .github/workflows/{clojure.yml => clojure-trunk.yml} (100%) diff --git a/.github/workflows/clojure-master.yml b/.github/workflows/clojure-master.yml new file mode 100644 index 0000000..e6d0a17 --- /dev/null +++ b/.github/workflows/clojure-master.yml @@ -0,0 +1,19 @@ +name: Clojure CI for master + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Install dependencies + run: lein deps + - name: Run tests + run: lein test diff --git a/.github/workflows/clojure.yml b/.github/workflows/clojure-trunk.yml similarity index 100% rename from .github/workflows/clojure.yml rename to .github/workflows/clojure-trunk.yml From d8c9c0ee5028de3ca4eb514592e598c698ba5d7f Mon Sep 17 00:00:00 2001 From: MelKori Date: Thu, 28 Oct 2021 15:13:07 +0300 Subject: [PATCH 10/10] update readme --- README.adoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.adoc b/README.adoc index 12ebc6d..c75b0b5 100644 --- a/README.adoc +++ b/README.adoc @@ -17,7 +17,7 @@ Add the following to your http://github.com/technomancy/leiningen[Leiningen's] ` [source,clojure] ---- -[net.tbt-post/zlib-tiny "0.4.0"] +[net.tbt-post/zlib-tiny "0.4.1"] ---- CAUTION: From version v0.3.2 and upward the library requires Java class versions 53.0 and newer (J11+), thus if in your needs is to use it with Java 1.8 please switch back to older (0.2.x) version of the library or try to rebuild the library locally. @@ -118,7 +118,7 @@ lein test zlib-tiny.checksum lein test zlib-tiny.compress -Ran 3 tests containing 8 assertions. +Ran 3 tests containing 10 assertions. 0 failures, 0 errors. ----