Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/4as/haxe-deflatex
Implementation of the deflate and inflate functions in pure Haxe.
https://github.com/4as/haxe-deflatex
compression cross-platform decompression deflate haxe haxelib inflate
Last synced: 7 days ago
JSON representation
Implementation of the deflate and inflate functions in pure Haxe.
- Host: GitHub
- URL: https://github.com/4as/haxe-deflatex
- Owner: 4as
- License: mit
- Created: 2022-08-21T11:17:07.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-09T14:45:12.000Z (almost 2 years ago)
- Last Synced: 2024-11-08T06:28:22.924Z (about 2 months ago)
- Topics: compression, cross-platform, decompression, deflate, haxe, haxelib, inflate
- Language: Haxe
- Homepage:
- Size: 19.5 KB
- Stars: 8
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
DeflateX is a Haxe port of the deflate/inflate implementation written by [RidgeX](https://github.com/RidgeX/deflate-impl) (hence the "X" in the name). Written purely in Haxe without any additional dependencies, it compiles to all available targets, but was tested only for JS, Flash, C++ (Windows), C# (Windows), PHP, Java, and HashLink.
# Usage
DeflateX provides not only the standard *deflate* and *inflate* algorithms, but also is able to compress and decompress gzip files.
Using DeflateX is pretty straightforward. If you want to compress a byte array simply pass it into the static `Deflater.apply` method.
`var test:String = "Test data 123";`
`var test_bytes:Bytes = Bytes.ofString(test);`
`var compressed:Bytes = Deflater.apply(test_bytes);`
However, in case you're working in a multi-threaded environment and want to run multiple deflate operations in parallel, you can also instantiate an unique `Deflater` object and call `compress` method instead:
`var deflater:Deflater = new Deflater();`
`var compressed:Bytes = deflater.compress(test_bytes);`
Once a byte array is deflated you can proceed to decompress it using the static `Inflater.apply` method:
`var decompressed:Bytes = Inflater.apply(compressed);`
`var result:String = decompressed.getString(0, decompressed.length);`
`trace(result); //following the Usage steps this should output "Test data 123"`
Or alternatively, as with `Deflater`, by instating the `Inflater` object and calling the `decompress` method:
`var inflater:Inflater = new Inflater();`
`var decompressed:Bytes = inflater.decompress(compressed);`
As for gzip files, those can be compressed and decompress using the static `compress` and `decompress` methods available in the `GZCompressor` class. Both are multi-thread safe.
# Installation
DeflateX can be installed by simply downloading the zipped source code from the Releases sub-page and extracting it into your project, or by using *haxelib*:
1. Install by executing command: `haxelib install deflatex`.
2. Add to your project by including `-lib deflatex` in your *hxml* file. Or `` if you're using OpenFL's `project.xml`.Once installed `Deflater` and `Inflater` classes should become available by importing the `deflatex` package.
# Disclaimer
DeflateX was tested by sending the deflated data to PHP's native [inflate method](https://www.php.net/manual/en/function.gzinflate.php) and verifying the correctness of the uncompressed data. However the algorithms were ported without any deeper considerations of the inner workings. If something doesn't match the official DEFLATE specification I probably won't be able to help with that.