Home

Awesome

BrotliHaxe

BrotliHaxe is a brotli compression decoder and encoder handported from original C to the Haxe Cross-platform-Toolkit that generate readable pure source code in JavaScript, PHP, Python, Java, C#, ActionScript and other.

New Features!

You can also:

Brotli is a generic-purpose lossless compression algorithm that compresses data using a combination of a modern variant of the LZ77 algorithm, Huffman coding and 2nd order context modeling, with a compression ratio comparable to the best currently available general-purpose compression methods. It is similar in speed with deflate but offers more dense compression. Brotli Github

Haxe is an open source toolkit that allows you to easily build cross-platform tools and applications that target many mainstream platforms. Haxe Github

BrotliHaxe author Dominik Homberger:

My hope is that people use Haxe to develop and port code to different platforms. It save worktime. Too, my hope is that Python and PHP source code developer optimise the programming language source so that the speed isn't more slower as JavaScript.

Build & Execute

BrotliHaxe requires Haxe 3.x when you want compile code. (I already put generated source to this git)

Important! This four files must be in the build dir:

If you upload the files to webserver then change to binary else you get error while decoding & encoding.

JavaScript

$ haxe -cp src -js ./javascript/brotli.js -main Main

For using as lib see source code at https://dominikhlbg.github.io/brotlijs/

PHP

$ haxe -cp src -php ./php/ -main Main
$ php ./php/index.php

Python

$ haxe -cp src -python ./python/brotli.py -main Main
$ python ./python/brotli.py

Java

$ haxe -cp src -java ./java/ -main Main
$ java -jar ./java/Main.jar

C#

$ haxe -cp src -cs ./cs/ -main Main

ActionScript

$ not implemented yet

Implement as Lib

Include the Brotli named file. (Java path: src/haxe/root/ else src/ or filename self)

include Brotli[.ext]

Build new Brotli()

var brotli = new Brotli();

You have four option. First both are string version.

var decompressedstring = brotli.decompress(compressedstring);
var compressedstring = brotli.compress(decompressedstring, quality); //quality [1...11]

The last two are byte array. [0...255]

var decompressedbytearray = brotli.decompressArray(compressedbytearray);
var compressedbytearray = brotli.compressArray(decompressedbytearray, quality); //quality [1...11]

Benchmark

Here you can see a small benchmark on an i7 2600k CPU.

Brotli Benchmark -q 1 plrabn12.txt

Languagecompressdecompress
JavaScript (v8)414190
PHP 5821144672
Python113395157
Java353100
C#40280
original C(++)2413

(ms) lower is better

Development

This source code base on a nearly two years old brotli version but still works good. I'm update to actually soon.

I'm looking for optimise the different outputs. Maybe you can help? Great! But the source code shouldn't looks different from the original source code because that makes updating difficult.

Todos

License

MIT

See license file and if you like you can add my name.

That is my first source code that I release under MIT!