zlib-tiny

Tiny & Lightweight Clojure ZLib helper

APACHE-2.0 License

Downloads
64.2K
Stars
7
Committers
3

= zlib-tiny

A Clojure library designed to cover basic needs of packing|unpacking exchange messages, storable chunks etc. And to check their consistency.

image:https://img.shields.io/github/license/source-c/zlib-tiny[GitHub] image:https://img.shields.io/clojars/v/net.tbt-post/zlib-tiny.svg[] image:https://img.shields.io/clojars/dt/net.tbt-post/zlib-tiny[ClojarsDownloads] image:https://img.shields.io/github/v/release/source-c/zlib-tiny[GitHub release (latest by date)] image:https://img.shields.io/github/release-date/source-c/zlib-tiny[GitHub Release Date] image:https://img.shields.io/github/v/tag/source-c/zlib-tiny[GitHub tag (latest by date)] image:https://img.shields.io/github/last-commit/source-c/zlib-tiny[GitHub last commit]

== Usage

Add the following to your http://github.com/technomancy/leiningen[Leiningen's] project.clj:

[source,clojure]

[net.tbt-post/zlib-tiny "0.5.0"]

CAUTION: From version v0.3.2 and upward the library may require Java class versions 53.0 and newer (J11+), thus if in your needs is to use it with some of Java 1.8, and the library build is not compatible with your version of Java, please switch back to older (0.2.x) version of the library (if your project not requires fresh features) or try to rebuild the library locally. We are doing our best to keep the library backward compatible with older Java versions, but unfortunately can not guaranty complete compatibility with wide range of java builds.

=== Compress

==== ZLib

[source,clojure]

;; ZLib Example

(bytes->str (force-byte-array (inflate (deflate (str->bytes "test it!")))))

(-> "test it!"
str->bytes
deflate
inflate
force-byte-array
bytes->str)

==== GZip

[source,clojure]

;; GZip Example

(bytes->str (gunzip (gzip (str->bytes "test it!"))))

(-> "test it!"
str->bytes
gzip
gunzip
bytes->str)

=== Checksums

==== CRC

[source,clojure]

;; CRC32 example
(crc32 (.getBytes "123456789"))
=> 3421780262

[source,clojure]

;; CRC32C example
(crc32c (.getBytes "123456789"))
=> 3808858755

[source,clojure]

;; CRC64 example
(crc64 (.getBytes "123456789"))
=> -7395533204333446662

==== Alternatives

[source,clojure]

;; Adler32 example
(adler32 (.getBytes "123456789"))
=> 152961502

==== Digests

[source,shell]

$ echo -n 'test it!' | md5 f4214812f0247f69661fd29e0fca6496

$ echo -n 'test it!' | shasum -a 1 1393ce5dfcf39109a420eb583ecfdeacc28c783a -

$ echo -n 'test it!' | shasum -a 256 9c507d01834b2749d088122a7b3d200957f9b25579b5ce6b490e3b2067ee4f66 -

$ echo -n 'test it!' | shasum -a 384 6e5cc5271b2255f2cf4154c3170c5fb09059c79d28d182ac2caa59bd607ea87c09637d8f2f7b400ac80810f13027716a -

$ echo -n 'test it!' | shasum -a 512
15353093ef47d2eadefc55d7bc641b6f1150e0b28a609d2368394748091f20b9125e98fe0603b2fbe57f9d65a9b286a8d0dbf70e8f597525051b6f9220e9b61f -

[source,clojure]

(-> "test it!" str->bytes md5 hexlify)
=> "f4214812f0247f69661fd29e0fca6496"
(-> "test it!" str->bytes sha-1 hexlify)
=> "1393ce5dfcf39109a420eb583ecfdeacc28c783a"
(-> "test it!" str->bytes sha-256 hexlify)
=> "9c507d01834b2749d088122a7b3d200957f9b25579b5ce6b490e3b2067ee4f66"
(-> "test it!" str->bytes sha-384 hexlify)
=> "6e5cc5271b2255f2cf4154c3170c5fb09059c79d28d182ac2caa59bd607ea87c09637d8f2f7b400ac80810f13027716a"
(-> "test it!" str->bytes sha-512 hexlify)
=> "15353093ef47d2eadefc55d7bc641b6f1150e0b28a609d2368394748091f20b9125e98fe0603b2fbe57f9d65a9b286a8d0dbf70e8f597525051b6f9220e9b61f"

== Test

[source,text]

$ lein test

...

lein test zlib-tiny.checksum Test input string: 123456789 Test input bytes: 313233343536373839 CRC32 checks: "Elapsed time: 0.034417 msecs" CRC32C checks: "Elapsed time: 0.037292 msecs" Adler32 checks: "Elapsed time: 0.316375 msecs" CRC64 checks: "Elapsed time: 0.210833 msecs"

lein test zlib-tiny.compress

Ran 3 tests containing 13 assertions.

== Manual Build

[source,text]

$ lein install

== License

Copyright © 2017-2023

Distributed under the http://www.apache.org/licenses/LICENSE-2.0[Apache License v 2.0]