public virtual object compressArray(object content, int quality) { unchecked { if (((quality < 0) || (quality > 11))) { global::haxe.Log.trace.__hx_invoke2_o(default(double), "Quality 0...11", default(double), new global::haxe.lang.DynamicObject(new int[] { 302979532, 1547539107, 1648581351 }, new object[] { "compressArray", "Brotli", "Brotli.hx" }, new int[] { 1981972957 }, new double[] { ((double)(268)) })); return(null); } global::Array <uint> fin = ((global::Array <uint>)(global::Array <object> .__hx_cast <uint>(((global::Array)(content))))); global::Array <uint> fout = new global::Array <uint>(); global::encode.encode.BrotliParams @params = new global::encode.encode.BrotliParams(); @params.quality = quality; global::encode.streams.BrotliMemOut output = new global::encode.streams.BrotliMemOut(((global::Array <uint>)(fout))); global::encode.Encode.BrotliCompress(@params, new global::encode.streams.BrotliMemIn(fin, fin.length), output); global::haxe.io.Bytes bytes = global::haxe.io.Bytes.alloc(output.position()); { int _g1 = 0; int _g = output.position(); while ((_g1 < _g)) { int i = _g1++; bytes.b[i] = ((byte)(((int)(output.buf_[i])))); } } return(output.buf_.slice(0, new global::haxe.lang.Null <int>(output.position(), true))); } }
public static void __hx_ctor_encode_encode_BrotliParams(global::encode.encode.BrotliParams __hx_this) { unchecked { __hx_this.mode = ((int)(0)); __hx_this.quality = 11; __hx_this.lgwin = 22; __hx_this.lgblock = 0; __hx_this.enable_dictionary = true; __hx_this.enable_transforms = false; __hx_this.greedy_block_split = false; __hx_this.enable_context_modeling = true; } }
public virtual object compress(object content, int quality) { unchecked { if (((quality < 0) || (quality > 11))) { global::haxe.Log.trace.__hx_invoke2_o(default(double), "Quality 0...11", default(double), new global::haxe.lang.DynamicObject(new int[] { 302979532, 1547539107, 1648581351 }, new object[] { "compress", "Brotli", "Brotli.hx" }, new int[] { 1981972957 }, new double[] { ((double)(243)) })); return(null); } global::Array <uint> fin = new global::Array <uint>(); { int _g1 = 0; int _g = ((int)(global::haxe.lang.Runtime.toInt(global::haxe.lang.Runtime.getField(content, "length", 520590566, true)))); while ((_g1 < _g)) { int i = _g1++; fin[i] = ((uint)(global::haxe.lang.Runtime.toInt(((object)(global::haxe.lang.Runtime.callField(content, "charCodeAt", 894756598, new global::Array <object>(new object[] { i }))))))); } } global::Array <uint> fout = new global::Array <uint>(); global::encode.encode.BrotliParams @params = new global::encode.encode.BrotliParams(); @params.quality = quality; global::encode.streams.BrotliMemOut output = new global::encode.streams.BrotliMemOut(((global::Array <uint>)(fout))); global::encode.Encode.BrotliCompress(@params, new global::encode.streams.BrotliMemIn(fin, fin.length), output); global::haxe.io.Bytes bytes = global::haxe.io.Bytes.alloc(output.position()); { int _g11 = 0; int _g2 = output.position(); while ((_g11 < _g2)) { int i1 = _g11++; bytes.b[i1] = ((byte)(((int)(output.buf_[i1])))); } } return(bytes.getString(0, output.position())); } }
public static bool BrotliCompressWithCustomDictionary(int dictsize, uint[] dict, global::encode.encode.BrotliParams @params, object input, object output) { int in_bytes = 0; global::Array <int> out_bytes = new global::Array <int>(new int[] { 0 }); global::Array <object> @out = new global::Array <object>(); bool final_block = false; global::encode.encode.BrotliCompressor compressor = new global::encode.encode.BrotliCompressor(((global::encode.encode.BrotliParams)(@params))); if ((dictsize != 0)) { compressor.BrotliSetCustomDictionary(dictsize, dict); } while (!(final_block)) { in_bytes = global::encode.Encode.CopyOneBlockToRingBuffer(input, compressor); if ((in_bytes != 0)) { final_block = global::encode.Encode.BrotliInIsFinished(input); } else { final_block = true; } out_bytes[0] = 0; if (!(compressor.WriteBrotliData(final_block, false, out_bytes, @out))) { return(false); } if (((out_bytes[0] > 0) && (!(global::haxe.lang.Runtime.toBool(((object)(global::haxe.lang.Runtime.callField(output, "Write", 1669782719, new global::Array <object>(new object[] { ((uint[])(@out[0])), out_bytes[0] }))))))))) { return(false); } } return(true); }
public static bool BrotliCompress(global::encode.encode.BrotliParams @params, object input, object output) { return(global::encode.Encode.BrotliCompressWithCustomDictionary(0, null, @params, input, output)); }
public static void main() { unchecked { global::Array <object> argv = global::Sys.args(); global::Array <object> input_path = new global::Array <object>(new object[] { "" }); global::Array <object> output_path = new global::Array <object>(new object[] { "" }); global::Array <int> force = new global::Array <int>(new int[] { 0 }); global::Array <int> quality = new global::Array <int>(new int[] { 11 }); global::Array <int> decompress = new global::Array <int>(new int[] { 0 }); if (!(global::Main.ParseArgv(argv.length, argv, input_path, output_path, force, quality, decompress))) { return; } if (!(global::sys.FileSystem.exists(global::haxe.lang.Runtime.toString(input_path[0])))) { global::System.Console.Write(((object)("Input Filename doesn\'t exists"))); return; } if ((global::sys.FileSystem.exists(global::haxe.lang.Runtime.toString(output_path[0])) && (force[0] == 0))) { global::System.Console.Write(((object)("Output Filename can\'t overwrite"))); return; } uint[] dictionary = global::Brotli.OpenInputBinary("dictionary.txt"); global::Date _this = new global::Date(((global::System.DateTime)(global::System.DateTime.Now))); double clock_start = (((double)(((long)((((long)(global::System.TimeZone.CurrentTimeZone.ToUniversalTime(((global::System.DateTime)(_this.date))).Ticks)) - ((long)(global::Date.epochTicks))))))) / ((double)(global::System.TimeSpan.TicksPerMillisecond))); global::sys.io.FileInput fin = global::Brotli.OpenInputFile(global::haxe.lang.Runtime.toString(input_path[0])); global::sys.io.FileOutput fout = global::Brotli.OpenOutputFile(global::haxe.lang.Runtime.toString(output_path[0]), force[0]); if ((decompress[0] > 0)) { global::decode.Dictionary.kBrotliDictionary = dictionary; global::Date _this1 = new global::Date(((global::System.DateTime)(global::System.DateTime.Now))); long __temp_expr3 = (((long)(global::System.TimeZone.CurrentTimeZone.ToUniversalTime(((global::System.DateTime)(_this1.date))).Ticks)) - ((long)(global::Date.epochTicks))); long __temp_expr4 = global::System.TimeSpan.TicksPerMillisecond; if ((global::decode.Decode.BrotliDecompress(global::decode.Streams.BrotliFileInput(fin), global::decode.Streams.BrotliFileOutput(fout)) <= 0)) { global::System.Console.Write(((object)("Error while decoding"))); return; } } else { global::encode.Dictionary.kBrotliDictionary = dictionary; uint[] DictionaryHash = global::Brotli.OpenInputBinary("DictionaryHash.txt"); uint[] DictionaryWords = global::Brotli.OpenInputBinary("DictionaryWords.txt"); uint[] DictionaryBuckets = global::Brotli.OpenInputBinary("DictionaryBuckets.txt"); global::Array <uint> kStaticDictionaryHash = global::encode.Dictionary_hash.kStaticDictionaryHash; global::Array <uint> kStaticDictionaryBuckets = global::encode.Static_dict_lut.kStaticDictionaryBuckets; { int _g = 0; while ((_g < 32768)) { int i = _g++; kStaticDictionaryHash.push(((uint)((((uint)((((uint)(((uint[])(DictionaryHash))[((i * 2) + 1)])) << 8))) | ((uint)(((uint[])(DictionaryHash))[(i * 2)])))))); kStaticDictionaryBuckets.push(((uint)((((uint)((((uint)((((uint)(((uint[])(DictionaryBuckets))[((i * 3) + 2)])) << 16))) | ((uint)((((uint)(((uint[])(DictionaryBuckets))[((i * 3) + 1)])) << 8)))))) | ((uint)(((uint[])(DictionaryBuckets))[(i * 3)])))))); } } global::Array <object> kStaticDictionaryWords = global::encode.Static_dict_lut.kStaticDictionaryWords; { int _g1 = 0; while ((_g1 < 31704)) { int i1 = _g1++; kStaticDictionaryWords.push(new global::encode.static_dict_lut.DictWord(((uint)(((uint)((((uint)(((uint)(((uint[])(DictionaryWords))[((i1 * 3) + 1)])))) >> 3))))), ((uint)(((uint[])(DictionaryWords))[((i1 * 3) + 2)])), ((uint)((((uint)(((((uint)((((uint)(((uint[])(DictionaryWords))[((i1 * 3) + 1)])) & 7)))) << 8))) | ((uint)(((uint[])(DictionaryWords))[(i1 * 3)]))))))); } } global::encode.encode.BrotliParams @params = new global::encode.encode.BrotliParams(); @params.quality = quality[0]; global::Date _this2 = new global::Date(((global::System.DateTime)(global::System.DateTime.Now))); long __temp_expr1 = (((long)(global::System.TimeZone.CurrentTimeZone.ToUniversalTime(((global::System.DateTime)(_this2.date))).Ticks)) - ((long)(global::Date.epochTicks))); long __temp_expr2 = global::System.TimeSpan.TicksPerMillisecond; if (!(global::encode.Encode.BrotliCompress(@params, new global::encode.streams.BrotliIn(fin, 65536), new global::encode.streams.BrotliOut(((global::sys.io.FileOutput)(fout)))))) { global::System.Console.Write(((object)("Error while encoding"))); return; } } global::Date _this3 = new global::Date(((global::System.DateTime)(global::System.DateTime.Now))); double duration = ((((((double)(((long)((((long)(global::System.TimeZone.CurrentTimeZone.ToUniversalTime(((global::System.DateTime)(_this3.date))).Ticks)) - ((long)(global::Date.epochTicks))))))) / ((double)(global::System.TimeSpan.TicksPerMillisecond))) - clock_start)) / 1000); if ((duration < 1e-9)) { duration = 1e-9; } if ((decompress[0] > 0)) { fout.tell(); } else { fin.tell(); } return; } }
public BrotliCompressor(global::encode.encode.BrotliParams @params) { global::encode.encode.BrotliCompressor.__hx_ctor_encode_encode_BrotliCompressor(this, @params); }
public override object __hx_setField(string field, int hash, object @value, bool handleProperties) { unchecked { switch (hash) { case 1327133892: { this.storage_ = ((uint[])(@value)); return(@value); } case 1934413114: { this.storage_size_ = ((int)(global::haxe.lang.Runtime.toInt(@value))); return(@value); } case 786269185: { this.prev_byte2_ = ((uint)(global::haxe.lang.Runtime.toInt(@value))); return(@value); } case 90195659: { this.prev_byte_ = ((uint)(global::haxe.lang.Runtime.toInt(@value))); return(@value); } case 1659886955: { this.last_byte_bits_ = ((uint)(global::haxe.lang.Runtime.toInt(@value))); return(@value); } case 1338359406: { this.last_byte_ = ((uint)(global::haxe.lang.Runtime.toInt(@value))); return(@value); } case 1854114270: { this.saved_dist_cache_ = ((int[])(@value)); return(@value); } case 35939030: { this.dist_cache_ = ((int[])(@value)); return(@value); } case 1044314085: { this.last_processed_pos_ = ((int)(global::haxe.lang.Runtime.toInt(@value))); return(@value); } case 282430831: { this.last_flush_pos_ = ((int)(global::haxe.lang.Runtime.toInt(@value))); return(@value); } case 537950791: { this.last_insert_len_ = ((int)(global::haxe.lang.Runtime.toInt(@value))); return(@value); } case 1358280002: { this.num_literals_ = ((int)(global::haxe.lang.Runtime.toInt(@value))); return(@value); } case 204352542: { this.num_commands_ = ((int)(global::haxe.lang.Runtime.toInt(@value))); return(@value); } case 1285881495: { this.commands_ = ((global::Array <object>)(global::Array <object> .__hx_cast <object>(((global::Array)(@value))))); return(@value); } case 770104548: { this.cmd_buffer_size_ = ((int)(global::haxe.lang.Runtime.toInt(@value))); return(@value); } case 194189137: { this.literal_cost_mask_ = ((int)(global::haxe.lang.Runtime.toInt(@value))); return(@value); } case 332919650: { this.literal_cost_ = ((double[])(@value)); return(@value); } case 439261615: { this.ringbuffer_ = ((global::encode.RingBuffer)(@value)); return(@value); } case 1752889312: { this.input_pos_ = ((int)(global::haxe.lang.Runtime.toInt(@value))); return(@value); } case 953005556: { this.hash_type_ = ((int)(global::haxe.lang.Runtime.toInt(@value))); return(@value); } case 502309127: { this.hashers_ = ((global::encode.hash.Hashers)(@value)); return(@value); } case 812293353: { this.max_backward_distance_ = ((int)(global::haxe.lang.Runtime.toInt(@value))); return(@value); } case 1579213401: { this.params_ = ((global::encode.encode.BrotliParams)(@value)); return(@value); } default: { return(base.__hx_setField(field, hash, @value, handleProperties)); } } } }
public static void __hx_ctor_encode_encode_BrotliCompressor(global::encode.encode.BrotliCompressor __hx_this, global::encode.encode.BrotliParams @params) { unchecked { { int[] this1 = null; this1 = new int[4]; __hx_this.saved_dist_cache_ = ((int[])(this1)); } { int[] this1 = null; this1 = new int[4]; __hx_this.dist_cache_ = ((int[])(this1)); } __hx_this.params_ = @params; __hx_this.hashers_ = new global::encode.hash.Hashers(); __hx_this.input_pos_ = 0; __hx_this.num_commands_ = 0; __hx_this.num_literals_ = 0; __hx_this.last_insert_len_ = 0; __hx_this.last_flush_pos_ = 0; __hx_this.last_processed_pos_ = 0; __hx_this.prev_byte_ = ((uint)(0)); __hx_this.prev_byte2_ = ((uint)(0)); __hx_this.storage_size_ = 0; double tmp = global::System.Math.Max(((double)(1)), ((double)(__hx_this.params_.quality))); __hx_this.params_.quality = ((int)(tmp)); if ((__hx_this.params_.lgwin < global::encode.Encode.kMinWindowBits)) { __hx_this.params_.lgwin = global::encode.Encode.kMinWindowBits; } else if ((__hx_this.params_.lgwin > global::encode.Encode.kMaxWindowBits)) { __hx_this.params_.lgwin = global::encode.Encode.kMaxWindowBits; } if ((__hx_this.params_.lgblock == 0)) { __hx_this.params_.lgblock = (((__hx_this.params_.quality < global::encode.Encode.kMinQualityForBlockSplit)) ? (14) : (16)); if (((__hx_this.params_.quality >= 9) && (__hx_this.params_.lgwin > __hx_this.params_.lgblock))) { double tmp1 = global::System.Math.Min(((double)(21)), ((double)(__hx_this.params_.lgwin))); __hx_this.params_.lgblock = ((int)(tmp1)); } } else { double tmp2 = global::System.Math.Min(((double)(global::encode.Encode.kMaxInputBlockBits)), ((double)(global::System.Math.Max(((double)(global::encode.Encode.kMinInputBlockBits)), ((double)(__hx_this.params_.lgblock)))))); __hx_this.params_.lgblock = ((int)(tmp2)); } __hx_this.max_backward_distance_ = (((1 << __hx_this.params_.lgwin)) - 16); __hx_this.ringbuffer_ = new global::encode.RingBuffer(((int)(global::System.Math.Max(((double)((__hx_this.params_.lgwin + 1))), ((double)((__hx_this.params_.lgblock + 1)))))), __hx_this.params_.lgblock); if ((__hx_this.params_.quality > 9)) { __hx_this.literal_cost_mask_ = (((1 << __hx_this.params_.lgblock)) - 1); __hx_this.literal_cost_ = global::FunctionMalloc.mallocFloat((__hx_this.literal_cost_mask_ + 1)); } __hx_this.cmd_buffer_size_ = ((int)(global::System.Math.Max(((double)(262144)), ((double)((1 << __hx_this.params_.lgblock)))))); __hx_this.commands_ = new global::Array <object>(); if ((__hx_this.params_.lgwin == 16)) { __hx_this.last_byte_ = ((uint)(0)); __hx_this.last_byte_bits_ = ((uint)(1)); } else if ((__hx_this.params_.lgwin == 17)) { __hx_this.last_byte_ = ((uint)(1)); __hx_this.last_byte_bits_ = ((uint)(7)); } else { __hx_this.last_byte_ = ((uint)((((__hx_this.params_.lgwin - 17) << 1) | 1))); __hx_this.last_byte_bits_ = ((uint)(4)); } ((int[])(__hx_this.dist_cache_))[0] = 4; ((int[])(__hx_this.dist_cache_))[1] = 11; ((int[])(__hx_this.dist_cache_))[2] = 15; ((int[])(__hx_this.dist_cache_))[3] = 16; global::DefaultFunctions.memcpy_Int(__hx_this.saved_dist_cache_, 0, __hx_this.dist_cache_, 0, (((int[])(__hx_this.dist_cache_)) as global::System.Array).Length); __hx_this.hash_type_ = ((int)(global::System.Math.Min(((double)(9)), ((double)(__hx_this.params_.quality))))); __hx_this.hashers_.Init(__hx_this.hash_type_); } }