Skip to content
This repository has been archived by the owner on Oct 26, 2023. It is now read-only.
/ zlib-tiny Public archive
forked from source-c/zlib-tiny

Tiny & Lightweight Clojure ZLib helper

License

Notifications You must be signed in to change notification settings

tbt-post/zlib-tiny

 
 

Repository files navigation

zlib-tiny

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

GitHub zlib tiny ClojarsDownloads GitHub release (latest by date) GitHub Release Date GitHub tag (latest by date) GitHub last commit

Usage

Add the following to your Leiningen’s project.clj:

[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

;; 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

;; GZip Example

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

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

Checksums

CRC

;; CRC32 example
(crc32 (.getBytes "123456789"))
=> 3421780262
;; CRC32C example
(crc32c (.getBytes "123456789"))
=> 3808858755
;; CRC64 example
(crc64 (.getBytes "123456789"))
=> -7395533204333446662

Alternatives

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

Digests

$ 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  -
(-> "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

$ 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

$ lein install

License

Copyright © 2017-2023

Distributed under the Apache License v 2.0

About

Tiny & Lightweight Clojure ZLib helper

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages

  • Clojure 55.0%
  • Java 45.0%