https://github.com/clj-commons/byte-transforms
methods for hashing, compressing, and encoding bytes
https://github.com/clj-commons/byte-transforms
Last synced: 2 months ago
JSON representation
methods for hashing, compressing, and encoding bytes
- Host: GitHub
- URL: https://github.com/clj-commons/byte-transforms
- Owner: clj-commons
- License: apache-2.0
- Created: 2013-07-25T01:48:08.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2022-07-28T06:52:46.000Z (almost 3 years ago)
- Last Synced: 2024-04-13T19:28:34.666Z (about 1 year ago)
- Language: Clojure
- Size: 792 KB
- Stars: 104
- Watchers: 8
- Forks: 10
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.adoc
- License: LICENSE.txt
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
[](https://clojars.org/org.clj-commons/byte-transforms)
[](https://cljdoc.org/d/clj-commons/byte-transforms)
[](https://circleci.com/gh/clj-commons/byte-transforms)This library helps you **hash**, **compress**, and **encode** streams of bytes. It contains the methods in the standard Java lib, as well as a curated collection of the best available methods.
## Usage
#### Leiningen
```clojure
[org.clj-commons/byte-transforms "0.2.1"]
```
#### deps.edn
```clojure
org.clj-commons/byte-transforms {:mvn/version "0.2.1"}
```All functions are in the `byte-transforms` namespace. There are five primary functions, `hash`, `compress`, `decompress`, `encode`, and `decode`. Each takes three arguments: the bytes, the method, and an (optional) options map. The bytes can be anything which is part of the [byte-stream](https://github.com/ztellman/byte-streams) conversion graph.
```clojure
byte-transforms> (hash "hello" :murmur64)
2191231550387646743byte-transforms> (compress "hello" :snappy)
#
byte-transforms> (byte-streams/to-string (decompress *1 :snappy))
"hello"byte-transforms> (byte-streams/to-string (encode "hello" :base64 {:url-safe? false}))
"aGVsbG8"
byte-transforms> (byte-streams/to-string (decode *1 :base64))
"hello"
```Note that Base64 encoding defaults to the [URL-safe](https://en.wikipedia.org/wiki/Base64#URL_applications) variant, which means that the output will not be padded. This can be disabled by passing in `{:url-safe? false}` to `encode`.
Available methods can be found via `available-hash-functions`, `available-compressors`, and `available-encoders`:
```clojure
byte-transforms> (available-hash-functions)
(:sha384 :md2 :crc32 :crc64 :sha512 :sha1 :murmur32 :murmur128 :adler32 :sha256 :md5 :murmur64)byte-transforms> (available-compressors)
(:lz4 :bzip2 :snappy :gzip)byte-transforms> (available-encoders)
(:base64)
```When choosing a compression algorithm, `snappy` is typically the fastest, `bzip2` yields the highest compression, and `lz4` provides a good balance between higher compression rate and fast decompression. All the compression algorithms except `lz4` are concat-able; multiple compressed segments can be concatenated and decompressed as a single stream.
Full stats on all methods can be found by cloning the project and running `lein test :benchmark`.
## License
Copyright © 2013 Zachary Tellman
Distributed under the Apache License 2.0.