From d8e19c30f461633841c8801becf58390c04d7305 Mon Sep 17 00:00:00 2001 From: Nidin Vinayakan <01@01alchemist.com> Date: Tue, 16 Feb 2016 02:06:08 +0100 Subject: [PATCH] Migrate to system js --- .travis.yml | 2 +- LICENSE | 2 +- build/es5/ByteArray.js | 1983 ----------------- build/es5/ByteArray.js.map | 1 - build/es6/ByteArray.js | 2 +- gulpfile.js | 2 +- package.json | 19 +- src/AMFHelper.ts | 621 ------ src/BitArray.ts | 99 - src/ByteArray.ts | 131 -- src/ByteArrayBase.ts | 1070 --------- src/CompressionAlgorithm.ts | 15 - src/HalfPrecisionWriter.ts | 126 -- src/IByteArray.ts | 16 - src/LZMAHelper.ts | 72 - src/MEMORY.ts | 40 - src/ZLIBHelper.ts | 65 - src/ctypes/Int64.ts | 54 +- src/ctypes/UInt64.ts | 54 +- src/ctypes/ctypes.d.ts | 2 - src/lzma/BitTreeDecoder.ts | 42 - src/lzma/LZMA.lib.d.ts | 7 - src/lzma/LZMA.ts | 134 -- src/lzma/LZMAWorker.ts | 34 - src/lzma/LenDecoder.ts | 41 - src/lzma/LzmaDecoder.ts | 319 --- src/lzma/OutWindow.ts | 66 - src/lzma/RangeDecoder.ts | 149 -- src/nid/lzma/BitTreeDecoder.ts | 39 + src/nid/lzma/LZMA.ts | 127 ++ src/nid/lzma/LZMAWorker.ts | 30 + src/nid/lzma/LenDecoder.ts | 40 + src/nid/lzma/LzmaDecoder.ts | 316 +++ src/nid/lzma/OutWindow.ts | 60 + src/nid/lzma/RangeDecoder.ts | 136 ++ src/nid/utils/AMFHelper.ts | 653 ++++++ src/nid/utils/BitArray.ts | 100 + src/nid/utils/ByteArray.ts | 1090 +++++++++ src/nid/utils/CompressionAlgorithm.ts | 12 + src/nid/utils/DataArray.ts | 133 ++ src/nid/utils/HalfPrecisionWriter.ts | 118 + src/nid/utils/LZMAHelper.ts | 75 + src/nid/utils/MEMORY.ts | 46 + src/nid/utils/StringUtils.ts | 33 + src/nid/utils/ZLIBHelper.ts | 70 + src/nid/zlib/Adler32.ts | 66 + src/nid/zlib/CRC32.ts | 107 + src/nid/zlib/CompressionMethod.ts | 18 + src/nid/zlib/Huffman.ts | 65 + src/nid/zlib/Inflate.ts | 108 + src/nid/zlib/RawInflate.ts | 691 ++++++ src/nid/zlib/ZLIB.ts | 23 + src/nid/zlib/ZLIBWorker.ts | 30 + src/utils/StringUtils.ts | 19 - src/zlib/Adler32.ts | 44 - src/zlib/CRC32.ts | 106 - src/zlib/CompressionMethod.ts | 22 - src/zlib/Huffman.ts | 70 - src/zlib/Inflate.ts | 108 - src/zlib/RawInflate.ts | 672 ------ src/zlib/ZLIB.lib.d.ts | 8 - src/zlib/ZLIB.ts | 24 - src/zlib/ZLIBWorker.ts | 34 - ...{ByteArrayTest.ts => ByteArrayUnitTest.ts} | 39 +- test/SimpleTest.ts | 20 + test/html/index-test.html | 21 - test/html/index.html | 26 - test/{html/lzma.html => lzma-test.html} | 0 test/simple-test.html | 20 + test/tsUnit.ts | 372 ++-- test/unit-test.html | 27 + tsconfig.json | 17 + 72 files changed, 4541 insertions(+), 6462 deletions(-) delete mode 100644 build/es5/ByteArray.js delete mode 100644 build/es5/ByteArray.js.map delete mode 100644 src/AMFHelper.ts delete mode 100644 src/BitArray.ts delete mode 100644 src/ByteArray.ts delete mode 100644 src/ByteArrayBase.ts delete mode 100644 src/CompressionAlgorithm.ts delete mode 100644 src/HalfPrecisionWriter.ts delete mode 100644 src/IByteArray.ts delete mode 100644 src/LZMAHelper.ts delete mode 100644 src/MEMORY.ts delete mode 100644 src/ZLIBHelper.ts delete mode 100644 src/ctypes/ctypes.d.ts delete mode 100644 src/lzma/BitTreeDecoder.ts delete mode 100644 src/lzma/LZMA.lib.d.ts delete mode 100644 src/lzma/LZMA.ts delete mode 100644 src/lzma/LZMAWorker.ts delete mode 100644 src/lzma/LenDecoder.ts delete mode 100644 src/lzma/LzmaDecoder.ts delete mode 100644 src/lzma/OutWindow.ts delete mode 100644 src/lzma/RangeDecoder.ts create mode 100644 src/nid/lzma/BitTreeDecoder.ts create mode 100644 src/nid/lzma/LZMA.ts create mode 100644 src/nid/lzma/LZMAWorker.ts create mode 100644 src/nid/lzma/LenDecoder.ts create mode 100644 src/nid/lzma/LzmaDecoder.ts create mode 100644 src/nid/lzma/OutWindow.ts create mode 100644 src/nid/lzma/RangeDecoder.ts create mode 100644 src/nid/utils/AMFHelper.ts create mode 100644 src/nid/utils/BitArray.ts create mode 100644 src/nid/utils/ByteArray.ts create mode 100644 src/nid/utils/CompressionAlgorithm.ts create mode 100644 src/nid/utils/DataArray.ts create mode 100644 src/nid/utils/HalfPrecisionWriter.ts create mode 100644 src/nid/utils/LZMAHelper.ts create mode 100644 src/nid/utils/MEMORY.ts create mode 100644 src/nid/utils/StringUtils.ts create mode 100644 src/nid/utils/ZLIBHelper.ts create mode 100644 src/nid/zlib/Adler32.ts create mode 100644 src/nid/zlib/CRC32.ts create mode 100644 src/nid/zlib/CompressionMethod.ts create mode 100644 src/nid/zlib/Huffman.ts create mode 100644 src/nid/zlib/Inflate.ts create mode 100644 src/nid/zlib/RawInflate.ts create mode 100644 src/nid/zlib/ZLIB.ts create mode 100644 src/nid/zlib/ZLIBWorker.ts delete mode 100644 src/utils/StringUtils.ts delete mode 100644 src/zlib/Adler32.ts delete mode 100644 src/zlib/CRC32.ts delete mode 100644 src/zlib/CompressionMethod.ts delete mode 100644 src/zlib/Huffman.ts delete mode 100644 src/zlib/Inflate.ts delete mode 100644 src/zlib/RawInflate.ts delete mode 100644 src/zlib/ZLIB.lib.d.ts delete mode 100644 src/zlib/ZLIB.ts delete mode 100644 src/zlib/ZLIBWorker.ts rename test/{ByteArrayTest.ts => ByteArrayUnitTest.ts} (89%) create mode 100644 test/SimpleTest.ts delete mode 100644 test/html/index-test.html delete mode 100644 test/html/index.html rename test/{html/lzma.html => lzma-test.html} (100%) create mode 100644 test/simple-test.html create mode 100644 test/unit-test.html create mode 100644 tsconfig.json diff --git a/.travis.yml b/.travis.yml index 19ceb28..3e009fd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,4 +5,4 @@ node_js: install: - "npm install" script: - - 'gulp' \ No newline at end of file + - 'node ./node_modules/typescript/bin/tsc -p ./' \ No newline at end of file diff --git a/LICENSE b/LICENSE index 2bf24b9..3dcd0c0 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) +Copyright (c) 2016 Nidin Vinayakan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/build/es5/ByteArray.js b/build/es5/ByteArray.js deleted file mode 100644 index 4fa77ea..0000000 --- a/build/es5/ByteArray.js +++ /dev/null @@ -1,1983 +0,0 @@ -/** - * JavaScript UInt64 - * version : 0.1 - * @author Nidin Vinayakan | nidinthb@gmail.com - * - */ -var ctypes; -(function (ctypes) { - var UInt64 = (function () { - function UInt64(low, high) { - if (low === void 0) { low = 0; } - if (high === void 0) { high = 0; } - this.low = low; - this.high = high; - } - UInt64.prototype.value = function () { - //this._value = (this.low | (this.high << 32)); - var _h = this.high.toString(16); - var _hd = 8 - _h.length; - if (_hd > 0) { - for (var i = 0; i < _hd; i++) { - _h = '0' + _h; - } - } - var _l = this.low.toString(16); - var _ld = 8 - _l.length; - if (_ld > 0) { - for (i = 0; i < _ld; i++) { - _l = '0' + _l; - } - } - this._value = Number('0x' + _h + _l); - return this._value; - }; - return UInt64; - })(); - ctypes.UInt64 = UInt64; -})(ctypes || (ctypes = {})); -/** - * JavaScript Int64 - * version : 0.1 - * @author Nidin Vinayakan | nidinthb@gmail.com - * - */ -var ctypes; -(function (ctypes) { - var Int64 = (function () { - function Int64(low, high) { - this.low = low; - this.high = high; - } - Int64.prototype.value = function () { - //this._value = (this.low | (this.high << 32)); - var _h = this.high.toString(16); - var _hd = 8 - _h.length; - if (_hd > 0) { - for (var i = 0; i < _hd; i++) { - _h = '0' + _h; - } - } - var _l = this.low.toString(16); - var _ld = 8 - _l.length; - if (_ld > 0) { - for (i = 0; i < _ld; i++) { - _l = '0' + _l; - } - } - this._value = Number('0x' + _h + _l); - return this._value; - }; - return Int64; - })(); - ctypes.Int64 = Int64; -})(ctypes || (ctypes = {})); -/// -/** -* JavaScript ByteArrayBase -* version : 0.2 -* @author Nidin Vinayakan | nidinthb@gmail.com -* -* ActionScript3 ByteArrayBase implementation in JavaScript -* limitation : size of ByteArrayBase cannot be changed -* -*/ -var nid; -(function (nid) { - var utils; - (function (utils) { - var UInt64 = ctypes.UInt64; - var Int64 = ctypes.Int64; - var ByteArrayBase = (function () { - function ByteArrayBase(buffer, offset, length) { - if (offset === void 0) { offset = 0; } - if (length === void 0) { length = 0; } - this.BUFFER_EXT_SIZE = 1024; //Buffer expansion size - this.array = null; - this.EOF_byte = -1; - this.EOF_code_point = -1; - if (buffer == undefined) { - buffer = new ArrayBuffer(this.BUFFER_EXT_SIZE); - this.write_position = 0; - } - else if (buffer == null) { - this.write_position = 0; - } - else { - this.write_position = length > 0 ? length : buffer.byteLength; - } - if (buffer) { - this.data = new DataView(buffer, offset, length > 0 ? length : buffer.byteLength); - } - this._position = 0; - this.endian = ByteArrayBase.BIG_ENDIAN; - } - Object.defineProperty(ByteArrayBase.prototype, "buffer", { - // getter setter - get: function () { - return this.data.buffer; - }, - set: function (value) { - this.data = new DataView(value); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(ByteArrayBase.prototype, "dataView", { - get: function () { - return this.data; - }, - set: function (value) { - this.data = value; - this.write_position = value.byteLength; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(ByteArrayBase.prototype, "phyPosition", { - get: function () { - return this._position + this.data.byteOffset; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(ByteArrayBase.prototype, "bufferOffset", { - get: function () { - return this.data.byteOffset; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(ByteArrayBase.prototype, "position", { - get: function () { - return this._position; - }, - set: function (value) { - if (this._position < value) { - if (!this.validate(this._position - value)) { - return; - } - } - this._position = value; - this.write_position = value > this.write_position ? value : this.write_position; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(ByteArrayBase.prototype, "length", { - get: function () { - return this.write_position; - }, - set: function (value) { - this.validateBuffer(value); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(ByteArrayBase.prototype, "bytesAvailable", { - get: function () { - return this.data.byteLength - this._position; - }, - enumerable: true, - configurable: true - }); - //end - ByteArrayBase.prototype.clear = function () { - this._position = 0; - }; - ByteArrayBase.prototype.getArray = function () { - if (this.array == null) { - this.array = new Uint8Array(this.data.buffer, this.data.byteOffset, this.data.byteLength); - } - return this.array; - }; - ByteArrayBase.prototype.setArray = function (array) { - this.array = array; - this.setBuffer(array.buffer, array.byteOffset, array.byteLength); - }; - ByteArrayBase.prototype.setBuffer = function (buffer, offset, length) { - if (offset === void 0) { offset = 0; } - if (length === void 0) { length = 0; } - if (buffer) { - this.data = new DataView(buffer, offset, length > 0 ? length : buffer.byteLength); - this.write_position = length > 0 ? length : buffer.byteLength; - } - else { - this.write_position = 0; - } - this._position = 0; - }; - /** - * Reads a Boolean value from the byte stream. A single byte is read, - * and true is returned if the byte is nonzero, - * false otherwise. - * @return Returns true if the byte is nonzero, false otherwise. - */ - ByteArrayBase.prototype.readBoolean = function () { - if (!this.validate(ByteArrayBase.SIZE_OF_BOOLEAN)) - return null; - return this.data.getUint8(this.position++) != 0; - }; - /** - * Reads a signed byte from the byte stream. - * The returned value is in the range -128 to 127. - * @return An integer between -128 and 127. - */ - ByteArrayBase.prototype.readByte = function () { - if (!this.validate(ByteArrayBase.SIZE_OF_INT8)) - return null; - return this.data.getInt8(this.position++); - }; - /** - * Reads the number of data bytes, specified by the length parameter, from the byte stream. - * The bytes are read into the ByteArrayBase object specified by the bytes parameter, - * and the bytes are written into the destination ByteArrayBase starting at the _position specified by offset. - * @param bytes The ByteArrayBase object to read data into. - * @param offset The offset (_position) in bytes at which the read data should be written. - * @param length The number of bytes to read. The default value of 0 causes all available data to be read. - */ - ByteArrayBase.prototype.readBytes = function (_bytes, offset, length, createNewBuffer) { - if (_bytes === void 0) { _bytes = null; } - if (offset === void 0) { offset = 0; } - if (length === void 0) { length = 0; } - if (createNewBuffer === void 0) { createNewBuffer = false; } - if (length == 0) { - length = this.bytesAvailable; - } - else if (!this.validate(length)) - return null; - if (createNewBuffer) { - _bytes = _bytes == null ? new ByteArrayBase(new ArrayBuffer(length)) : _bytes; - //This method is expensive - for (var i = 0; i < length; i++) { - _bytes.data.setUint8(i + offset, this.data.getUint8(this.position++)); - } - } - else { - //Offset argument ignored - _bytes = _bytes == null ? new ByteArrayBase(null) : _bytes; - _bytes.dataView = new DataView(this.data.buffer, this.bufferOffset + this.position, length); - this.position += length; - } - return _bytes; - }; - /** - * Reads an IEEE 754 double-precision (64-bit) floating-point number from the byte stream. - * @return A double-precision (64-bit) floating-point number. - */ - ByteArrayBase.prototype.readDouble = function () { - if (!this.validate(ByteArrayBase.SIZE_OF_FLOAT64)) - return null; - var value = this.data.getFloat64(this.position, this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_FLOAT64; - return value; - }; - /** - * Reads an IEEE 754 single-precision (32-bit) floating-point number from the byte stream. - * @return A single-precision (32-bit) floating-point number. - */ - ByteArrayBase.prototype.readFloat = function () { - if (!this.validate(ByteArrayBase.SIZE_OF_FLOAT32)) - return null; - var value = this.data.getFloat32(this.position, this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_FLOAT32; - return value; - }; - /** - * Reads a signed 32-bit integer from the byte stream. - * - * The returned value is in the range -2147483648 to 2147483647. - * @return A 32-bit signed integer between -2147483648 and 2147483647. - */ - ByteArrayBase.prototype.readInt = function () { - if (!this.validate(ByteArrayBase.SIZE_OF_INT32)) - return null; - var value = this.data.getInt32(this.position, this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_INT32; - return value; - }; - /** - * Reads a signed 64-bit integer from the byte stream. - * - * The returned value is in the range −(2^63) to 2^63 − 1 - * @return A 64-bit signed integer between −(2^63) to 2^63 − 1 - */ - ByteArrayBase.prototype.readInt64 = function () { - if (!this.validate(ByteArrayBase.SIZE_OF_UINT32)) - return null; - var low = this.data.getInt32(this.position, this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_INT32; - var high = this.data.getInt32(this.position, this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_INT32; - return new Int64(low, high); - }; - /** - * Reads a multibyte string of specified length from the byte stream using the - * specified character set. - * @param length The number of bytes from the byte stream to read. - * @param charSet The string denoting the character set to use to interpret the bytes. - * Possible character set strings include "shift-jis", "cn-gb", - * "iso-8859-1", and others. - * For a complete list, see Supported Character Sets. - * Note: If the value for the charSet parameter - * is not recognized by the current system, the application uses the system's default - * code page as the character set. For example, a value for the charSet parameter, - * as in myTest.readMultiByte(22, "iso-8859-01") that uses 01 instead of - * 1 might work on your development system, but not on another system. - * On the other system, the application will use the system's default code page. - * @return UTF-8 encoded string. - */ - ByteArrayBase.prototype.readMultiByte = function (length, charSet) { - if (!this.validate(length)) - return null; - return ""; - }; - /** - * Reads a signed 16-bit integer from the byte stream. - * - * The returned value is in the range -32768 to 32767. - * @return A 16-bit signed integer between -32768 and 32767. - */ - ByteArrayBase.prototype.readShort = function () { - if (!this.validate(ByteArrayBase.SIZE_OF_INT16)) - return null; - var value = this.data.getInt16(this.position, this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_INT16; - return value; - }; - /** - * Reads an unsigned byte from the byte stream. - * - * The returned value is in the range 0 to 255. - * @return A 32-bit unsigned integer between 0 and 255. - */ - ByteArrayBase.prototype.readUnsignedByte = function () { - if (!this.validate(ByteArrayBase.SIZE_OF_UINT8)) - return null; - return this.data.getUint8(this.position++); - }; - /** - * Reads an unsigned 32-bit integer from the byte stream. - * - * The returned value is in the range 0 to 4294967295. - * @return A 32-bit unsigned integer between 0 and 4294967295. - */ - ByteArrayBase.prototype.readUnsignedInt = function () { - if (!this.validate(ByteArrayBase.SIZE_OF_UINT32)) - return null; - var value = this.data.getUint32(this.position, this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_UINT32; - return value; - }; - /** - * Reads a variable sized unsigned integer (VX -> 16-bit or 32-bit) from the byte stream. - * - * A VX is written as a variable length 2- or 4-byte element. If the index value is less than 65,280 (0xFF00), - * then the index is written as an unsigned two-byte integer. Otherwise the index is written as an unsigned - * four byte integer with bits 24-31 set. When reading an index, if the first byte encountered is 255 (0xFF), - * then the four-byte form is being used and the first byte should be discarded or masked out. - * - * The returned value is in the range 0 to 65279 or 0 to 2147483647. - * @return A VX 16-bit or 32-bit unsigned integer between 0 to 65279 or 0 and 2147483647. - */ - ByteArrayBase.prototype.readVariableSizedUnsignedInt = function () { - var value; - var c = this.readUnsignedByte(); - if (c != 0xFF) { - value = c << 8; - c = this.readUnsignedByte(); - value |= c; - } - else { - c = this.readUnsignedByte(); - value = c << 16; - c = this.readUnsignedByte(); - value |= c << 8; - c = this.readUnsignedByte(); - value |= c; - } - return value; - }; - /** - * Fast read for WebGL since only Uint16 numbers are expected - */ - ByteArrayBase.prototype.readU16VX = function () { - return (this.readUnsignedByte() << 8) | this.readUnsignedByte(); - }; - /** - * Reads an unsigned 64-bit integer from the byte stream. - * - * The returned value is in the range 0 to 2^64 − 1. - * @return A 64-bit unsigned integer between 0 and 2^64 − 1 - */ - ByteArrayBase.prototype.readUnsignedInt64 = function () { - if (!this.validate(ByteArrayBase.SIZE_OF_UINT32)) - return null; - var low = this.data.getUint32(this.position, this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_UINT32; - var high = this.data.getUint32(this.position, this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_UINT32; - return new UInt64(low, high); - }; - /** - * Reads an unsigned 16-bit integer from the byte stream. - * - * The returned value is in the range 0 to 65535. - * @return A 16-bit unsigned integer between 0 and 65535. - */ - ByteArrayBase.prototype.readUnsignedShort = function () { - if (!this.validate(ByteArrayBase.SIZE_OF_UINT16)) - return null; - var value = this.data.getUint16(this.position, this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_UINT16; - return value; - }; - /** - * Reads a UTF-8 string from the byte stream. The string - * is assumed to be prefixed with an unsigned short indicating - * the length in bytes. - * @return UTF-8 encoded string. - */ - ByteArrayBase.prototype.readUTF = function () { - if (!this.validate(ByteArrayBase.SIZE_OF_UINT16)) - return null; - var length = this.data.getUint16(this.position, this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_UINT16; - if (length > 0) { - return this.readUTFBytes(length); - } - else { - return ""; - } - }; - /** - * Reads a sequence of UTF-8 bytes specified by the length - * parameter from the byte stream and returns a string. - * @param length An unsigned short indicating the length of the UTF-8 bytes. - * @return A string composed of the UTF-8 bytes of the specified length. - */ - ByteArrayBase.prototype.readUTFBytes = function (length) { - if (!this.validate(length)) - return null; - var _bytes = new Uint8Array(this.buffer, this.bufferOffset + this.position, length); - this.position += length; - /*var _bytes: Uint8Array = new Uint8Array(new ArrayBuffer(length)); - for (var i = 0; i < length; i++) { - _bytes[i] = this.data.getUint8(this.position++); - }*/ - return this.decodeUTF8(_bytes); - }; - ByteArrayBase.prototype.readStandardString = function (length) { - if (!this.validate(length)) - return null; - var str = ""; - for (var i = 0; i < length; i++) { - str += String.fromCharCode(this.data.getUint8(this.position++)); - } - return str; - }; - ByteArrayBase.prototype.readStringTillNull = function (keepEvenByte) { - if (keepEvenByte === void 0) { keepEvenByte = true; } - var str = ""; - var num = 0; - while (this.bytesAvailable > 0) { - var _byte = this.data.getUint8(this.position++); - num++; - if (_byte != 0) { - str += String.fromCharCode(_byte); - } - else { - if (keepEvenByte && num % 2 != 0) { - this.position++; - } - break; - } - } - return str; - }; - /** - * Writes a Boolean value. A single byte is written according to the value parameter, - * either 1 if true or 0 if false. - * @param value A Boolean value determining which byte is written. If the parameter is true, - * the method writes a 1; if false, the method writes a 0. - */ - ByteArrayBase.prototype.writeBoolean = function (value) { - this.validateBuffer(ByteArrayBase.SIZE_OF_BOOLEAN); - this.data.setUint8(this.position++, value ? 1 : 0); - }; - /** - * Writes a byte to the byte stream. - * The low 8 bits of the - * parameter are used. The high 24 bits are ignored. - * @param value A 32-bit integer. The low 8 bits are written to the byte stream. - */ - ByteArrayBase.prototype.writeByte = function (value) { - this.validateBuffer(ByteArrayBase.SIZE_OF_INT8); - this.data.setInt8(this.position++, value); - }; - ByteArrayBase.prototype.writeUnsignedByte = function (value) { - this.validateBuffer(ByteArrayBase.SIZE_OF_UINT8); - this.data.setUint8(this.position++, value); - }; - /** - * Writes a sequence of length bytes from the - * specified byte array, bytes, - * starting offset(zero-based index) bytes - * into the byte stream. - * - * If the length parameter is omitted, the default - * length of 0 is used; the method writes the entire buffer starting at - * offset. - * If the offset parameter is also omitted, the entire buffer is - * written. If offset or length - * is out of range, they are clamped to the beginning and end - * of the bytes array. - * @param bytes The ByteArrayBase object. - * @param offset A zero-based index indicating the _position into the array to begin writing. - * @param length An unsigned integer indicating how far into the buffer to write. - */ - ByteArrayBase.prototype.writeBytes = function (_bytes, offset, length) { - if (offset === void 0) { offset = 0; } - if (length === void 0) { length = 0; } - this.validateBuffer(length); - var tmp_data = new DataView(_bytes.buffer); - for (var i = 0; i < _bytes.length; i++) { - this.data.setUint8(this.position++, tmp_data.getUint8(i)); - } - }; - /** - * Writes an IEEE 754 double-precision (64-bit) floating-point number to the byte stream. - * @param value A double-precision (64-bit) floating-point number. - */ - ByteArrayBase.prototype.writeDouble = function (value) { - this.validateBuffer(ByteArrayBase.SIZE_OF_FLOAT64); - this.data.setFloat64(this.position, value, this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_FLOAT64; - }; - /** - * Writes an IEEE 754 single-precision (32-bit) floating-point number to the byte stream. - * @param value A single-precision (32-bit) floating-point number. - */ - ByteArrayBase.prototype.writeFloat = function (value) { - this.validateBuffer(ByteArrayBase.SIZE_OF_FLOAT32); - this.data.setFloat32(this.position, value, this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_FLOAT32; - }; - /** - * Writes a 32-bit signed integer to the byte stream. - * @param value An integer to write to the byte stream. - */ - ByteArrayBase.prototype.writeInt = function (value) { - this.validateBuffer(ByteArrayBase.SIZE_OF_INT32); - this.data.setInt32(this.position, value, this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_INT32; - }; - /** - * Writes a multibyte string to the byte stream using the specified character set. - * @param value The string value to be written. - * @param charSet The string denoting the character set to use. Possible character set strings - * include "shift-jis", "cn-gb", "iso-8859-1", and others. - * For a complete list, see Supported Character Sets. - */ - ByteArrayBase.prototype.writeMultiByte = function (value, charSet) { - }; - /** - * Writes a 16-bit integer to the byte stream. The low 16 bits of the parameter are used. - * The high 16 bits are ignored. - * @param value 32-bit integer, whose low 16 bits are written to the byte stream. - */ - ByteArrayBase.prototype.writeShort = function (value) { - this.validateBuffer(ByteArrayBase.SIZE_OF_INT16); - this.data.setInt16(this.position, value, this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_INT16; - }; - ByteArrayBase.prototype.writeUnsignedShort = function (value) { - this.validateBuffer(ByteArrayBase.SIZE_OF_UINT16); - this.data.setUint16(this.position, value, this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_UINT16; - }; - /** - * Writes a 32-bit unsigned integer to the byte stream. - * @param value An unsigned integer to write to the byte stream. - */ - ByteArrayBase.prototype.writeUnsignedInt = function (value) { - this.validateBuffer(ByteArrayBase.SIZE_OF_UINT32); - this.data.setUint32(this.position, value, this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_UINT32; - }; - /** - * Writes a UTF-8 string to the byte stream. The length of the UTF-8 string in bytes - * is written first, as a 16-bit integer, followed by the bytes representing the - * characters of the string. - * @param value The string value to be written. - */ - ByteArrayBase.prototype.writeUTF = function (value) { - var utf8bytes = this.encodeUTF8(value); - var length = utf8bytes.length; - this.validateBuffer(ByteArrayBase.SIZE_OF_UINT16 + length); - this.data.setUint16(this.position, length, this.endian === ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_UINT16; - this.writeUint8Array(utf8bytes); - }; - /** - * Writes a UTF-8 string to the byte stream. Similar to the writeUTF() method, - * but writeUTFBytes() does not prefix the string with a 16-bit length word. - * @param value The string value to be written. - */ - ByteArrayBase.prototype.writeUTFBytes = function (value) { - this.writeUint8Array(this.encodeUTF8(value)); - }; - ByteArrayBase.prototype.toString = function () { - return "[ByteArrayBase] length:" + this.length + ", bytesAvailable:" + this.bytesAvailable; - }; - /****************************/ - /* EXTRA JAVASCRIPT APIs */ - /****************************/ - /** - * Writes a Uint8Array to the byte stream. - * @param value The Uint8Array to be written. - */ - ByteArrayBase.prototype.writeUint8Array = function (_bytes) { - this.validateBuffer(this.position + _bytes.length); - for (var i = 0; i < _bytes.length; i++) { - this.data.setUint8(this.position++, _bytes[i]); - } - }; - /** - * Writes a Uint16Array to the byte stream. - * @param value The Uint16Array to be written. - */ - ByteArrayBase.prototype.writeUint16Array = function (_bytes) { - this.validateBuffer(this.position + _bytes.length); - for (var i = 0; i < _bytes.length; i++) { - this.data.setUint16(this.position, _bytes[i], this.endian === ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_UINT16; - } - }; - /** - * Writes a Uint32Array to the byte stream. - * @param value The Uint32Array to be written. - */ - ByteArrayBase.prototype.writeUint32Array = function (_bytes) { - this.validateBuffer(this.position + _bytes.length); - for (var i = 0; i < _bytes.length; i++) { - this.data.setUint32(this.position, _bytes[i], this.endian === ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_UINT32; - } - }; - /** - * Writes a Int8Array to the byte stream. - * @param value The Int8Array to be written. - */ - ByteArrayBase.prototype.writeInt8Array = function (_bytes) { - this.validateBuffer(this.position + _bytes.length); - for (var i = 0; i < _bytes.length; i++) { - this.data.setInt8(this.position++, _bytes[i]); - } - }; - /** - * Writes a Int16Array to the byte stream. - * @param value The Int16Array to be written. - */ - ByteArrayBase.prototype.writeInt16Array = function (_bytes) { - this.validateBuffer(this.position + _bytes.length); - for (var i = 0; i < _bytes.length; i++) { - this.data.setInt16(this.position, _bytes[i], this.endian === ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_INT16; - } - }; - /** - * Writes a Int32Array to the byte stream. - * @param value The Int32Array to be written. - */ - ByteArrayBase.prototype.writeInt32Array = function (_bytes) { - this.validateBuffer(this.position + _bytes.length); - for (var i = 0; i < _bytes.length; i++) { - this.data.setInt32(this.position, _bytes[i], this.endian === ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_INT32; - } - }; - /** - * Writes a Float32Array to the byte stream. - * @param value The Float32Array to be written. - */ - ByteArrayBase.prototype.writeFloat32Array = function (_bytes) { - this.validateBuffer(this.position + _bytes.length); - for (var i = 0; i < _bytes.length; i++) { - this.data.setFloat32(this.position, _bytes[i], this.endian === ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_FLOAT32; - } - }; - /** - * Writes a Float64Array to the byte stream. - * @param value The Float64Array to be written. - */ - ByteArrayBase.prototype.writeFloat64Array = function (_bytes) { - this.validateBuffer(this.position + _bytes.length); - for (var i = 0; i < _bytes.length; i++) { - this.data.setFloat64(this.position, _bytes[i], this.endian === ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_FLOAT64; - } - }; - /** - * Read a Uint8Array from the byte stream. - * @param length An unsigned short indicating the length of the Uint8Array. - */ - ByteArrayBase.prototype.readUint8Array = function (length, createNewBuffer) { - if (createNewBuffer === void 0) { createNewBuffer = true; } - if (!this.validate(length)) - return null; - if (!createNewBuffer) { - var result = new Uint8Array(this.buffer, this.bufferOffset + this.position, length); - this.position += length; - } - else { - result = new Uint8Array(new ArrayBuffer(length)); - for (var i = 0; i < length; i++) { - result[i] = this.data.getUint8(this.position); - this.position += ByteArrayBase.SIZE_OF_UINT8; - } - } - return result; - }; - /** - * Read a Uint16Array from the byte stream. - * @param length An unsigned short indicating the length of the Uint16Array. - */ - ByteArrayBase.prototype.readUint16Array = function (length, createNewBuffer) { - if (createNewBuffer === void 0) { createNewBuffer = true; } - var size = length * ByteArrayBase.SIZE_OF_UINT16; - if (!this.validate(size)) - return null; - if (!createNewBuffer) { - var result = new Uint16Array(this.buffer, this.bufferOffset + this.position, length); - this.position += size; - } - else { - result = new Uint16Array(new ArrayBuffer(size)); - for (var i = 0; i < length; i++) { - result[i] = this.data.getUint16(this.position, this.endian === ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_UINT16; - } - } - return result; - }; - /** - * Read a Uint32Array from the byte stream. - * @param length An unsigned short indicating the length of the Uint32Array. - */ - ByteArrayBase.prototype.readUint32Array = function (length, createNewBuffer) { - if (createNewBuffer === void 0) { createNewBuffer = true; } - var size = length * ByteArrayBase.SIZE_OF_UINT32; - if (!this.validate(size)) - return null; - if (!createNewBuffer) { - var result = new Uint32Array(this.buffer, this.bufferOffset + this.position, length); - this.position += size; - } - else { - result = new Uint32Array(new ArrayBuffer(size)); - for (var i = 0; i < length; i++) { - result[i] = this.data.getUint32(this.position, this.endian === ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_UINT32; - } - } - return result; - }; - /** - * Read a Int8Array from the byte stream. - * @param length An unsigned short indicating the length of the Int8Array. - */ - ByteArrayBase.prototype.readInt8Array = function (length, createNewBuffer) { - if (createNewBuffer === void 0) { createNewBuffer = true; } - if (!this.validate(length)) - return null; - if (!createNewBuffer) { - var result = new Int8Array(this.buffer, this.bufferOffset + this.position, length); - this.position += length; - } - else { - result = new Int8Array(new ArrayBuffer(length)); - for (var i = 0; i < length; i++) { - result[i] = this.data.getInt8(this.position); - this.position += ByteArrayBase.SIZE_OF_INT8; - } - } - return result; - }; - /** - * Read a Int16Array from the byte stream. - * @param length An unsigned short indicating the length of the Int16Array. - */ - ByteArrayBase.prototype.readInt16Array = function (length, createNewBuffer) { - if (createNewBuffer === void 0) { createNewBuffer = true; } - var size = length * ByteArrayBase.SIZE_OF_INT16; - if (!this.validate(size)) - return null; - if (!createNewBuffer) { - var result = new Int16Array(this.buffer, this.bufferOffset + this.position, length); - this.position += size; - } - else { - result = new Int16Array(new ArrayBuffer(size)); - for (var i = 0; i < length; i++) { - result[i] = this.data.getInt16(this.position, this.endian === ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_INT16; - } - } - return result; - }; - /** - * Read a Int32Array from the byte stream. - * @param length An unsigned short indicating the length of the Int32Array. - */ - ByteArrayBase.prototype.readInt32Array = function (length, createNewBuffer) { - if (createNewBuffer === void 0) { createNewBuffer = true; } - var size = length * ByteArrayBase.SIZE_OF_INT32; - if (!this.validate(size)) - return null; - if (!createNewBuffer) { - if ((this.bufferOffset + this.position) % 4 == 0) { - var result = new Int32Array(this.buffer, this.bufferOffset + this.position, length); - this.position += size; - } - else { - var tmp = new Uint8Array(new ArrayBuffer(size)); - for (var i = 0; i < size; i++) { - tmp[i] = this.data.getUint8(this.position); - this.position += ByteArrayBase.SIZE_OF_UINT8; - } - result = new Int32Array(tmp.buffer); - } - } - else { - result = new Int32Array(new ArrayBuffer(size)); - for (var i = 0; i < length; i++) { - result[i] = this.data.getInt32(this.position, this.endian === ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_INT32; - } - } - return result; - }; - /** - * Read a Float32Array from the byte stream. - * @param length An unsigned short indicating the length of the Float32Array. - */ - ByteArrayBase.prototype.readFloat32Array = function (length, createNewBuffer) { - if (createNewBuffer === void 0) { createNewBuffer = true; } - var size = length * ByteArrayBase.SIZE_OF_FLOAT32; - if (!this.validate(size)) - return null; - if (!createNewBuffer) { - if ((this.bufferOffset + this.position) % 4 == 0) { - var result = new Float32Array(this.buffer, this.bufferOffset + this.position, length); - this.position += size; - } - else { - var tmp = new Uint8Array(new ArrayBuffer(size)); - for (var i = 0; i < size; i++) { - tmp[i] = this.data.getUint8(this.position); - this.position += ByteArrayBase.SIZE_OF_UINT8; - } - result = new Float32Array(tmp.buffer); - } - } - else { - result = new Float32Array(new ArrayBuffer(size)); - for (var i = 0; i < length; i++) { - result[i] = this.data.getFloat32(this.position, this.endian === ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_FLOAT32; - } - } - return result; - }; - /** - * Read a Float64Array from the byte stream. - * @param length An unsigned short indicating the length of the Float64Array. - */ - ByteArrayBase.prototype.readFloat64Array = function (length, createNewBuffer) { - if (createNewBuffer === void 0) { createNewBuffer = true; } - var size = length * ByteArrayBase.SIZE_OF_FLOAT64; - if (!this.validate(size)) - return null; - if (!createNewBuffer) { - var result = new Float64Array(this.buffer, this.position, length); - this.position += size; - } - else { - result = new Float64Array(new ArrayBuffer(size)); - for (var i = 0; i < length; i++) { - result[i] = this.data.getFloat64(this.position, this.endian === ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_FLOAT64; - } - } - return result; - }; - ByteArrayBase.prototype.validate = function (len) { - //len += this.data.byteOffset; - if (this.data.byteLength > 0 && this._position + len <= this.data.byteLength) { - return true; - } - else { - throw 'Error #2030: End of file was encountered.'; - } - }; - /**********************/ - /* PRIVATE METHODS */ - /**********************/ - ByteArrayBase.prototype.validateBuffer = function (len) { - this.write_position = len > this.write_position ? len : this.write_position; - if (this.data.byteLength < len) { - var tmp = new Uint8Array(new ArrayBuffer(len + this.BUFFER_EXT_SIZE)); - tmp.set(new Uint8Array(this.data.buffer)); - this.data.buffer = tmp.buffer; - } - }; - /** - * UTF-8 Encoding/Decoding - */ - ByteArrayBase.prototype.encodeUTF8 = function (str) { - var pos = 0; - var codePoints = this.stringToCodePoints(str); - var outputBytes = []; - while (codePoints.length > pos) { - var code_point = codePoints[pos++]; - if (this.inRange(code_point, 0xD800, 0xDFFF)) { - this.encoderError(code_point); - } - else if (this.inRange(code_point, 0x0000, 0x007f)) { - outputBytes.push(code_point); - } - else { - var count, offset; - if (this.inRange(code_point, 0x0080, 0x07FF)) { - count = 1; - offset = 0xC0; - } - else if (this.inRange(code_point, 0x0800, 0xFFFF)) { - count = 2; - offset = 0xE0; - } - else if (this.inRange(code_point, 0x10000, 0x10FFFF)) { - count = 3; - offset = 0xF0; - } - outputBytes.push(this.div(code_point, Math.pow(64, count)) + offset); - while (count > 0) { - var temp = this.div(code_point, Math.pow(64, count - 1)); - outputBytes.push(0x80 + (temp % 64)); - count -= 1; - } - } - } - return new Uint8Array(outputBytes); - }; - ByteArrayBase.prototype.decodeUTF8 = function (data) { - var fatal = false; - var pos = 0; - var result = ""; - var code_point; - var utf8_code_point = 0; - var utf8_bytes_needed = 0; - var utf8_bytes_seen = 0; - var utf8_lower_boundary = 0; - while (data.length > pos) { - var _byte = data[pos++]; - if (_byte === this.EOF_byte) { - if (utf8_bytes_needed !== 0) { - code_point = this.decoderError(fatal); - } - else { - code_point = this.EOF_code_point; - } - } - else { - if (utf8_bytes_needed === 0) { - if (this.inRange(_byte, 0x00, 0x7F)) { - code_point = _byte; - } - else { - if (this.inRange(_byte, 0xC2, 0xDF)) { - utf8_bytes_needed = 1; - utf8_lower_boundary = 0x80; - utf8_code_point = _byte - 0xC0; - } - else if (this.inRange(_byte, 0xE0, 0xEF)) { - utf8_bytes_needed = 2; - utf8_lower_boundary = 0x800; - utf8_code_point = _byte - 0xE0; - } - else if (this.inRange(_byte, 0xF0, 0xF4)) { - utf8_bytes_needed = 3; - utf8_lower_boundary = 0x10000; - utf8_code_point = _byte - 0xF0; - } - else { - this.decoderError(fatal); - } - utf8_code_point = utf8_code_point * Math.pow(64, utf8_bytes_needed); - code_point = null; - } - } - else if (!this.inRange(_byte, 0x80, 0xBF)) { - utf8_code_point = 0; - utf8_bytes_needed = 0; - utf8_bytes_seen = 0; - utf8_lower_boundary = 0; - pos--; - code_point = this.decoderError(fatal, _byte); - } - else { - utf8_bytes_seen += 1; - utf8_code_point = utf8_code_point + (_byte - 0x80) * Math.pow(64, utf8_bytes_needed - utf8_bytes_seen); - if (utf8_bytes_seen !== utf8_bytes_needed) { - code_point = null; - } - else { - var cp = utf8_code_point; - var lower_boundary = utf8_lower_boundary; - utf8_code_point = 0; - utf8_bytes_needed = 0; - utf8_bytes_seen = 0; - utf8_lower_boundary = 0; - if (this.inRange(cp, lower_boundary, 0x10FFFF) && !this.inRange(cp, 0xD800, 0xDFFF)) { - code_point = cp; - } - else { - code_point = this.decoderError(fatal, _byte); - } - } - } - } - //Decode string - if (code_point !== null && code_point !== this.EOF_code_point) { - if (code_point <= 0xFFFF) { - if (code_point > 0) - result += String.fromCharCode(code_point); - } - else { - code_point -= 0x10000; - result += String.fromCharCode(0xD800 + ((code_point >> 10) & 0x3ff)); - result += String.fromCharCode(0xDC00 + (code_point & 0x3ff)); - } - } - } - return result; - }; - ByteArrayBase.prototype.encoderError = function (code_point) { - throw 'EncodingError! The code point ' + code_point + ' could not be encoded.'; - }; - ByteArrayBase.prototype.decoderError = function (fatal, opt_code_point) { - if (fatal) { - throw 'DecodingError'; - } - return opt_code_point || 0xFFFD; - }; - ByteArrayBase.prototype.inRange = function (a, min, max) { - return min <= a && a <= max; - }; - ByteArrayBase.prototype.div = function (n, d) { - return Math.floor(n / d); - }; - ByteArrayBase.prototype.stringToCodePoints = function (string) { - /** @type {Array.} */ - var cps = []; - // Based on http://www.w3.org/TR/WebIDL/#idl-DOMString - var i = 0, n = string.length; - while (i < string.length) { - var c = string.charCodeAt(i); - if (!this.inRange(c, 0xD800, 0xDFFF)) { - cps.push(c); - } - else if (this.inRange(c, 0xDC00, 0xDFFF)) { - cps.push(0xFFFD); - } - else { - if (i === n - 1) { - cps.push(0xFFFD); - } - else { - var d = string.charCodeAt(i + 1); - if (this.inRange(d, 0xDC00, 0xDFFF)) { - var a = c & 0x3FF; - var b = d & 0x3FF; - i += 1; - cps.push(0x10000 + (a << 10) + b); - } - else { - cps.push(0xFFFD); - } - } - } - i += 1; - } - return cps; - }; - ByteArrayBase.BIG_ENDIAN = "bigEndian"; - ByteArrayBase.LITTLE_ENDIAN = "littleEndian"; - ByteArrayBase.SIZE_OF_BOOLEAN = 1; - ByteArrayBase.SIZE_OF_INT8 = 1; - ByteArrayBase.SIZE_OF_INT16 = 2; - ByteArrayBase.SIZE_OF_INT32 = 4; - ByteArrayBase.SIZE_OF_INT64 = 8; - ByteArrayBase.SIZE_OF_UINT8 = 1; - ByteArrayBase.SIZE_OF_UINT16 = 2; - ByteArrayBase.SIZE_OF_UINT32 = 4; - ByteArrayBase.SIZE_OF_UINT64 = 8; - ByteArrayBase.SIZE_OF_FLOAT32 = 4; - ByteArrayBase.SIZE_OF_FLOAT64 = 8; - return ByteArrayBase; - })(); - utils.ByteArrayBase = ByteArrayBase; - })(utils = nid.utils || (nid.utils = {})); -})(nid || (nid = {})); -var nid; -(function (nid) { - var utils; - (function (utils) { - var MEMORY = (function () { - function MEMORY() { - } - MEMORY.allocateUint8 = function (len) { - MEMORY.u8 = new Uint8Array(len); - }; - MEMORY.allocateUint16 = function (len) { - MEMORY.u16 = new Uint16Array(len); - }; - MEMORY.allocateUint32 = function (len) { - MEMORY.u32 = new Uint32Array(len); - }; - MEMORY.getUint8 = function () { - if (!MEMORY.u8) { - MEMORY.allocateUint8(10); - } - return MEMORY.u8Index++; - }; - MEMORY.getUint16 = function () { - if (!MEMORY.u16) { - MEMORY.allocateUint16(24); - } - return MEMORY.u16Index++; - }; - MEMORY.getUint32 = function () { - if (!MEMORY.u32) { - MEMORY.allocateUint32(10); - } - return MEMORY.u32Index++; - }; - MEMORY.u8Index = 0; - MEMORY.u16Index = 0; - MEMORY.u32Index = 0; - return MEMORY; - })(); - utils.MEMORY = MEMORY; - })(utils = nid.utils || (nid.utils = {})); -})(nid || (nid = {})); -/// -var nid; -(function (nid) { - var utils; - (function (utils) { - /** - * LZMA Decoder - * @author Nidin Vinayakan | nidinthb@gmail.com - */ - var MEMORY = nid.utils.MEMORY; - var LzmaDecoder = (function () { - function LzmaDecoder() { - this.posSlotDecoder = utils.BitTreeDecoder.constructArray(6, utils.LZMA.kNumLenToPosStates); //6 - this.alignDecoder = new utils.BitTreeDecoder(utils.LZMA.kNumAlignBits); - this.posDecoders = new Uint16Array(1 + utils.LZMA.kNumFullDistances - utils.LZMA.kEndPosModelIndex); - this.isMatch = new Uint16Array(utils.LZMA.kNumStates << utils.LZMA.kNumPosBitsMax); - this.isRep = new Uint16Array(utils.LZMA.kNumStates); - this.isRepG0 = new Uint16Array(utils.LZMA.kNumStates); - this.isRepG1 = new Uint16Array(utils.LZMA.kNumStates); - this.isRepG2 = new Uint16Array(utils.LZMA.kNumStates); - this.isRep0Long = new Uint16Array(utils.LZMA.kNumStates << utils.LZMA.kNumPosBitsMax); - this.lenDecoder = new utils.LenDecoder(); - this.repLenDecoder = new utils.LenDecoder(); - this.rangeDec = new utils.RangeDecoder(); - this.outWindow = new utils.OutWindow(); - } - LzmaDecoder.prototype.init = function () { - this.loc1 = MEMORY.getUint32() | 0; - this.loc2 = MEMORY.getUint32() | 0; - this.matchBitI = MEMORY.getUint16() | 0; - this.matchByteI = MEMORY.getUint16() | 0; - this.bitI = MEMORY.getUint16() | 0; - this.symbolI = MEMORY.getUint16() | 0; - this.prevByteI = MEMORY.getUint16() | 0; - this.litStateI = MEMORY.getUint16() | 0; - this.initLiterals(); - this.initDist(); - utils.LZMA.INIT_PROBS(this.isMatch); - utils.LZMA.INIT_PROBS(this.isRep); - utils.LZMA.INIT_PROBS(this.isRepG0); - utils.LZMA.INIT_PROBS(this.isRepG1); - utils.LZMA.INIT_PROBS(this.isRepG2); - utils.LZMA.INIT_PROBS(this.isRep0Long); - this.lenDecoder.init(); - this.repLenDecoder.init(); - }; - LzmaDecoder.prototype.create = function () { - this.outWindow.create(this.dictSize); - this.createLiterals(); - }; - //Private - LzmaDecoder.prototype.createLiterals = function () { - this.litProbs = new Uint16Array(0x300 << (this.lc + this.lp)); - }; - LzmaDecoder.prototype.initLiterals = function () { - var num = 0x300 << (this.lc + this.lp); //UInt32 - for (var i = 0; i < num; i++) { - this.litProbs[i] = utils.LZMA.PROB_INIT_VAL; - } - }; - LzmaDecoder.prototype.decodeLiteral = function (state, rep0) { - MEMORY.u16[this.prevByteI] = 0; //unsigned byte - if (!this.outWindow.isEmpty()) - MEMORY.u16[this.prevByteI] = this.outWindow.getByte(1); - MEMORY.u16[this.symbolI] = 1; - MEMORY.u16[this.litStateI] = ((this.outWindow.totalPos & ((1 << this.lp) - 1)) << this.lc) + (MEMORY.u16[this.prevByteI] >>> (8 - this.lc)); - var probsOffset = (0x300 * MEMORY.u16[this.litStateI]) | 0; - if (state >= 7) { - MEMORY.u16[this.matchByteI] = this.outWindow.getByte(rep0 + 1); - do { - MEMORY.u16[this.matchBitI] = (MEMORY.u16[this.matchByteI] >>> 7) & 1; - MEMORY.u16[this.matchByteI] <<= 1; - MEMORY.u16[this.bitI] = this.rangeDec.decodeBit(this.litProbs, probsOffset + ((1 + MEMORY.u16[this.matchBitI]) << 8) + MEMORY.u16[this.symbolI]); - MEMORY.u16[this.symbolI] = (MEMORY.u16[this.symbolI] << 1) | MEMORY.u16[this.bitI]; - if (MEMORY.u16[this.matchBitI] != MEMORY.u16[this.bitI]) - break; - } while (MEMORY.u16[this.symbolI] < 0x100); - } - while (MEMORY.u16[this.symbolI] < 0x100) { - MEMORY.u16[this.symbolI] = (MEMORY.u16[this.symbolI] << 1) | this.rangeDec.decodeBit(this.litProbs, probsOffset + MEMORY.u16[this.symbolI]); - } - this.outWindow.putByte(MEMORY.u16[this.symbolI] - 0x100); - }; - LzmaDecoder.prototype.decodeDistance = function (len) { - var lenState = len; //unsigned byte - if (lenState > utils.LZMA.kNumLenToPosStates - 1) - lenState = utils.LZMA.kNumLenToPosStates - 1; - var posSlot = this.posSlotDecoder[lenState].decode(this.rangeDec); //unsigned byte - if (posSlot < 4) - return posSlot; - var numDirectBits = ((posSlot >>> 1) - 1); //unsigned byte - MEMORY.u32[this.loc1] = ((2 | (posSlot & 1)) << numDirectBits); //UInt32 - if (posSlot < utils.LZMA.kEndPosModelIndex) { - MEMORY.u32[this.loc1] += utils.LZMA.BitTreeReverseDecode(this.posDecoders, numDirectBits, this.rangeDec, MEMORY.u32[this.loc1] - posSlot); - } - else { - MEMORY.u32[this.loc1] += this.rangeDec.decodeDirectBits(numDirectBits - utils.LZMA.kNumAlignBits) << utils.LZMA.kNumAlignBits; - MEMORY.u32[this.loc1] += this.alignDecoder.reverseDecode(this.rangeDec); - } - return MEMORY.u32[this.loc1]; - }; - LzmaDecoder.prototype.initDist = function () { - for (var i = 0; i < utils.LZMA.kNumLenToPosStates; i++) { - this.posSlotDecoder[i].init(); - } - this.alignDecoder.init(); - utils.LZMA.INIT_PROBS(this.posDecoders); - }; - LzmaDecoder.prototype.decodeProperties = function (properties) { - var prop = new Uint8Array(4); - prop[0] = properties[0]; - if (prop[0] >= (9 * 5 * 5)) { - throw "Incorrect LZMA properties"; - } - prop[1] = prop[0] % 9; - prop[0] /= 9; - prop[2] = prop[0] / 5; - prop[3] = prop[0] % 5; - this.lc = prop[1]; - this.pb = prop[2]; - this.lp = prop[3]; - this.dictSizeInProperties = 0; - for (var i = 0; i < 4; i++) { - this.dictSizeInProperties |= properties[i + 1] << (8 * i); - } - this.dictSize = this.dictSizeInProperties; - if (this.dictSize < utils.LZMA.LZMA_DIC_MIN) { - this.dictSize = utils.LZMA.LZMA_DIC_MIN; - } - }; - LzmaDecoder.prototype.updateState_Literal = function (state) { - if (state < 4) - return 0; - else if (state < 10) - return state - 3; - else - return state - 6; - }; - LzmaDecoder.prototype.updateState_ShortRep = function (state) { return state < 7 ? 9 : 11; }; - LzmaDecoder.prototype.updateState_Rep = function (state) { return state < 7 ? 8 : 11; }; - LzmaDecoder.prototype.updateState_Match = function (state) { return state < 7 ? 7 : 10; }; - LzmaDecoder.prototype.decode = function (unpackSizeDefined, unpackSize) { - this.init(); - this.rangeDec.init(); - if (unpackSizeDefined) { - this.outWindow.outStream = new Uint8Array(new ArrayBuffer(unpackSize)); - } - var rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0; //UInt32 - var state = 0; //unsigned byte - for (;;) { - if (unpackSizeDefined && unpackSize == 0 && !this.markerIsMandatory) { - if (this.rangeDec.isFinishedOK()) { - return utils.LZMA.LZMA_RES_FINISHED_WITHOUT_MARKER; - } - } - var posState = this.outWindow.totalPos & ((1 << this.pb) - 1); - if (this.rangeDec.decodeBit(this.isMatch, (state << utils.LZMA.kNumPosBitsMax) + posState) == 0) { - if (unpackSizeDefined && unpackSize == 0) { - return utils.LZMA.LZMA_RES_ERROR; - } - this.decodeLiteral(state, rep0); - state = this.updateState_Literal(state); - unpackSize--; - continue; - } - var len; - if (this.rangeDec.decodeBit(this.isRep, state) != 0) { - if (unpackSizeDefined && unpackSize == 0) { - return utils.LZMA.LZMA_RES_ERROR; - } - if (this.outWindow.isEmpty()) { - return utils.LZMA.LZMA_RES_ERROR; - } - if (this.rangeDec.decodeBit(this.isRepG0, state) == 0) { - if (this.rangeDec.decodeBit(this.isRep0Long, (state << utils.LZMA.kNumPosBitsMax) + posState) == 0) { - state = this.updateState_ShortRep(state); - this.outWindow.putByte(this.outWindow.getByte(rep0 + 1)); - unpackSize--; - continue; - } - } - else { - var dist; - if (this.rangeDec.decodeBit(this.isRepG1, state) == 0) { - dist = rep1; - } - else { - if (this.rangeDec.decodeBit(this.isRepG2, state) == 0) { - dist = rep2; - } - else { - dist = rep3; - rep3 = rep2; - } - rep2 = rep1; - } - rep1 = rep0; - rep0 = dist; - } - len = this.repLenDecoder.decode(this.rangeDec, posState); - state = this.updateState_Rep(state); - } - else { - rep3 = rep2; - rep2 = rep1; - rep1 = rep0; - len = this.lenDecoder.decode(this.rangeDec, posState); - state = this.updateState_Match(state); - rep0 = this.decodeDistance(len); - if (rep0 == 0xFFFFFFFF) { - return this.rangeDec.isFinishedOK() ? - utils.LZMA.LZMA_RES_FINISHED_WITH_MARKER : - utils.LZMA.LZMA_RES_ERROR; - } - if (unpackSizeDefined && unpackSize == 0) { - return utils.LZMA.LZMA_RES_ERROR; - } - if (rep0 >= this.dictSize || !this.outWindow.checkDistance(rep0)) { - return utils.LZMA.LZMA_RES_ERROR; - } - } - len += utils.LZMA.kMatchMinLen; - var isError = false; - if (unpackSizeDefined && unpackSize < len) { - len = unpackSize; - isError = true; - } - this.outWindow.copyMatch(rep0 + 1, len); - unpackSize -= len; - if (isError) { - return utils.LZMA.LZMA_RES_ERROR; - } - } - }; - return LzmaDecoder; - })(); - utils.LzmaDecoder = LzmaDecoder; - })(utils = nid.utils || (nid.utils = {})); -})(nid || (nid = {})); -var nid; -(function (nid) { - var utils; - (function (utils) { - /** - * LZMA Decoder - * @author Nidin Vinayakan | nidinthb@gmail.com - */ - var OutWindow = (function () { - function OutWindow() { - this.out_pos = 0; - } - OutWindow.prototype.create = function (dictSize) { - this.buf = new Uint8Array(dictSize); - this.pos = 0; - this.size = dictSize; - this.isFull = false; - this.totalPos = 0; - }; - OutWindow.prototype.putByte = function (b) { - this.totalPos++; - this.buf[this.pos++] = b; - if (this.pos == this.size) { - this.pos = 0; - this.isFull = true; - } - //this.outStream.writeUnsignedByte(b); - this.outStream[this.out_pos++] = b; - }; - OutWindow.prototype.getByte = function (dist) { - return this.buf[dist <= this.pos ? this.pos - dist : this.size - dist + this.pos]; - }; - OutWindow.prototype.copyMatch = function (dist, len) { - for (; len > 0; len--) { - this.putByte(this.getByte(dist)); - } - }; - OutWindow.prototype.checkDistance = function (dist) { - return dist <= this.pos || this.isFull; - }; - OutWindow.prototype.isEmpty = function () { - return this.pos == 0 && !this.isFull; - }; - return OutWindow; - })(); - utils.OutWindow = OutWindow; - })(utils = nid.utils || (nid.utils = {})); -})(nid || (nid = {})); -/// -var nid; -(function (nid) { - var utils; - (function (utils) { - var RangeDecoder = (function () { - function RangeDecoder() { - this.rangeI = 0; - this.codeI = 1; - this.loc1 = 2; - this.loc2 = 3; - this.in_pos = 13; - } - RangeDecoder.prototype.isFinishedOK = function () { - return this.U32[this.codeI] == 0; - }; - RangeDecoder.prototype.init = function () { - this.U32 = new Uint32Array(4); - this.U16 = new Uint16Array(4); - this.corrupted = false; - if (this.inStream[this.in_pos++] != 0) { - this.corrupted = true; - } - this.U32[this.rangeI] = 0xFFFFFFFF; - this.U32[this.codeI] = 0; - for (var i = 0; i < 4; i++) { - this.U32[this.codeI] = (this.U32[this.codeI] << 8) | this.inStream[this.in_pos++]; - } - if (this.U32[this.codeI] == this.U32[this.rangeI]) { - this.corrupted = true; - } - }; - RangeDecoder.prototype.normalize = function () { - if (this.U32[this.rangeI] < RangeDecoder.kTopValue) { - this.U32[this.rangeI] <<= 8; - this.U32[this.codeI] = (this.U32[this.codeI] << 8) | this.inStream[this.in_pos++]; - } - }; - RangeDecoder.prototype.decodeDirectBits = function (numBits) { - this.U32[this.loc1] = 0; //UInt32 - do { - this.U32[this.rangeI] >>>= 1; - this.U32[this.codeI] -= this.U32[this.rangeI]; - this.U32[this.loc2] = 0 - (this.U32[this.codeI] >>> 31); - this.U32[this.codeI] += this.U32[this.rangeI] & this.U32[this.loc2]; - if (this.U32[this.codeI] == this.U32[this.rangeI]) { - this.corrupted = true; - } - this.normalize(); - this.U32[this.loc1] <<= 1; - this.U32[this.loc1] += this.U32[this.loc2] + 1; - } while (--numBits); - return this.U32[this.loc1]; - }; - RangeDecoder.prototype.decodeBit = function (prob, index) { - this.U16[0] = prob[index]; - //bound - this.U32[2] = (this.U32[0] >>> 11) * this.U16[0]; - //var symbol:number; - if (this.U32[1] < this.U32[2]) { - this.U16[0] += ((1 << 11) - this.U16[0]) >>> 5; - this.U32[0] = this.U32[2]; - this.U16[1] = 0; - } - else { - //v -= v >>> LZMA.kNumMoveBits; - this.U16[0] -= this.U16[0] >>> 5; - this.U32[1] -= this.U32[2]; - this.U32[0] -= this.U32[2]; - this.U16[1] = 1; - } - prob[index] = this.U16[0]; - //this.normalize(); - if (this.U32[0] < 16777216) { - this.U32[0] <<= 8; - this.U32[1] = (this.U32[1] << 8) | this.inStream[this.in_pos++]; - } - return this.U16[1]; - }; - RangeDecoder.kTopValue = (1 << 24); - return RangeDecoder; - })(); - utils.RangeDecoder = RangeDecoder; - })(utils = nid.utils || (nid.utils = {})); -})(nid || (nid = {})); -/// -var nid; -(function (nid) { - var utils; - (function (utils) { - /** - * LZMA Decoder - * @author Nidin Vinayakan | nidinthb@gmail.com - */ - var BitTreeDecoder = (function () { - function BitTreeDecoder(numBits) { - this.numBits = numBits; - this.probs = new Uint16Array(1 << this.numBits); - } - BitTreeDecoder.prototype.init = function () { - utils.LZMA.INIT_PROBS(this.probs); - }; - BitTreeDecoder.prototype.decode = function (rc) { - var m = 1; //Uint16 - for (var i = 0; i < this.numBits; i++) - m = (m << 1) + rc.decodeBit(this.probs, m); - return m - (1 << this.numBits); - }; - BitTreeDecoder.prototype.reverseDecode = function (rc) { - return utils.LZMA.BitTreeReverseDecode(this.probs, this.numBits, rc); - }; - BitTreeDecoder.constructArray = function (numBits, len) { - var vec = []; - for (var i = 0; i < len; i++) { - vec[i] = new BitTreeDecoder(numBits); - } - return vec; - }; - return BitTreeDecoder; - })(); - utils.BitTreeDecoder = BitTreeDecoder; - })(utils = nid.utils || (nid.utils = {})); -})(nid || (nid = {})); -/// -var nid; -(function (nid) { - var utils; - (function (utils) { - /** - * LZMA Decoder - * @author Nidin Vinayakan | nidinthb@gmail.com - */ - var LenDecoder = (function () { - function LenDecoder() { - this.lowCoder = utils.BitTreeDecoder.constructArray(3, 1 << utils.LZMA.kNumPosBitsMax); - this.midCoder = utils.BitTreeDecoder.constructArray(3, 1 << utils.LZMA.kNumPosBitsMax); - this.highCoder = new utils.BitTreeDecoder(8); - } - LenDecoder.prototype.init = function () { - this.choice = [utils.LZMA.PROB_INIT_VAL, utils.LZMA.PROB_INIT_VAL]; - this.highCoder.init(); - for (var i = 0; i < (1 << utils.LZMA.kNumPosBitsMax); i++) { - this.lowCoder[i].init(); - this.midCoder[i].init(); - } - }; - LenDecoder.prototype.decode = function (rc, posState) { - if (rc.decodeBit(this.choice, 0) == 0) { - return this.lowCoder[posState].decode(rc); - } - if (rc.decodeBit(this.choice, 1) == 0) { - return 8 + this.midCoder[posState].decode(rc); - } - return 16 + this.highCoder.decode(rc); - }; - return LenDecoder; - })(); - utils.LenDecoder = LenDecoder; - })(utils = nid.utils || (nid.utils = {})); -})(nid || (nid = {})); -/// -var nid; -(function (nid) { - var utils; - (function (utils) { - "use strict"; - /** - * LZMA Decoder - * @author Nidin Vinayakan | nidinthb@gmail.com - * - */ - var LZMA = (function () { - function LZMA() { - this.decoder = new utils.LzmaDecoder(); - } - LZMA.INIT_PROBS = function (p) { - for (var i = 0; i < p.length; i++) { - p[i] = this.PROB_INIT_VAL; - } - }; - LZMA.BitTreeReverseDecode = function (probs, numBits, rc, offset) { - if (offset === void 0) { offset = 0; } - var m = 1; - var symbol = 0; - for (var i = 0; i < numBits; i++) { - var bit = rc.decodeBit(probs, offset + m); - m <<= 1; - m += bit; - symbol |= (bit << i); - } - return symbol; - }; - LZMA.prototype.decode = function (data) { - this.data = data; - //var header:Uint8Array = data.readUint8Array(13); - var header = new Uint8Array(13); - var i; //int - for (i = 0; i < 13; i++) { - header[i] = data[i]; - } - this.decoder.decodeProperties(header); - console.log("\nlc=" + this.decoder.lc + ", lp=" + this.decoder.lp + ", pb=" + this.decoder.pb); - console.log("\nDictionary Size in properties = " + this.decoder.dictSizeInProperties); - console.log("\nDictionary Size for decoding = " + this.decoder.dictSize); - //return this.ucdata; - var unpackSize = 0; //UInt64 - var unpackSizeDefined = false; - for (i = 0; i < 8; i++) { - var b = header[5 + i]; - if (b != 0xFF) { - unpackSizeDefined = true; - } - unpackSize |= b << (8 * i); - } - this.decoder.markerIsMandatory = !unpackSizeDefined; - console.log("\n"); - if (unpackSizeDefined) { - console.log("Uncompressed Size : " + unpackSize + " bytes"); - } - else { - console.log("End marker is expected\n"); - } - this.decoder.rangeDec.inStream = data; - console.log("\n"); - this.decoder.create(); - // we support the streams that have uncompressed size and marker. - var res = this.decoder.decode(unpackSizeDefined, unpackSize); //int - console.log("Read ", this.decoder.rangeDec.in_pos); - console.log("Written ", this.decoder.outWindow.out_pos); - if (res == LZMA.LZMA_RES_ERROR) { - throw "LZMA decoding error"; - } - else if (res == LZMA.LZMA_RES_FINISHED_WITHOUT_MARKER) { - console.log("Finished without end marker"); - } - else if (res == LZMA.LZMA_RES_FINISHED_WITH_MARKER) { - if (unpackSizeDefined) { - if (this.decoder.outWindow.out_pos != unpackSize) { - throw "Finished with end marker before than specified size"; - } - console.log("Warning: "); - } - console.log("Finished with end marker"); - } - else { - throw "Internal Error"; - } - console.log("\n"); - if (this.decoder.rangeDec.corrupted) { - console.log("\nWarning: LZMA stream is corrupted\n"); - } - return this.decoder.outWindow.outStream; - }; - LZMA.LZMA_DIC_MIN = (1 << 12); - LZMA.LZMA_RES_ERROR = 0; - LZMA.LZMA_RES_FINISHED_WITH_MARKER = 1; - LZMA.LZMA_RES_FINISHED_WITHOUT_MARKER = 2; - LZMA.kNumBitModelTotalBits = 11; - LZMA.kNumMoveBits = 5; - LZMA.PROB_INIT_VAL = ((1 << LZMA.kNumBitModelTotalBits) / 2); //1024 - LZMA.kNumPosBitsMax = 4; - LZMA.kNumStates = 12; - LZMA.kNumLenToPosStates = 4; - LZMA.kNumAlignBits = 4; - LZMA.kStartPosModelIndex = 4; - LZMA.kEndPosModelIndex = 14; - LZMA.kNumFullDistances = (1 << (LZMA.kEndPosModelIndex >>> 1)); - LZMA.kMatchMinLen = 2; - return LZMA; - })(); - utils.LZMA = LZMA; - })(utils = nid.utils || (nid.utils = {})); -})(nid || (nid = {})); -/// -var nid; -(function (nid) { - var utils; - (function (utils) { - var LZMAHelper = (function () { - function LZMAHelper() { - } - LZMAHelper.init = function () { - var command = 0; - if (LZMAHelper.enableAsync) { - LZMAHelper.decoderAsync = new Worker('LZMAWorker.min.js'); - LZMAHelper.decoderAsync.onmessage = function (e) { - if (command == 0) { - command = e.data; - } - else if (command == LZMAHelper.ENCODE) { - command = 0; //encode not implemented - } - else if (command == LZMAHelper.DECODE) { - command = 0; - LZMAHelper.callback(e.data); - LZMAHelper.callback = null; - } - }; - } - }; - /** - * TODO : Implement encoder - * @param data - * @returns {null} - */ - LZMAHelper.encode = function (data) { - return null; - }; - LZMAHelper.decodeBuffer = function (data) { - return LZMAHelper.decoder.decode(new Uint8Array(data)).buffer; - }; - LZMAHelper.decode = function (data) { - return LZMAHelper.decoder.decode(data); - }; - /** - * TODO : Implement encoder - * @param data - * @param _callback - */ - LZMAHelper.encodeAsync = function (data, _callback) { - if (LZMAHelper.enableAsync) { - } - else { - console.log('Error! Asynchronous encoding is disabled'); - } - }; - LZMAHelper.decodeAsync = function (data, _callback) { - if (LZMAHelper.enableAsync) { - if (LZMAHelper.callback == null) { - LZMAHelper.callback = _callback; - LZMAHelper.decoderAsync.postMessage(LZMAHelper.DECODE); - LZMAHelper.decoderAsync.postMessage(data, [data]); - } - else { - console.log('Warning! Another LZMA decoding is running...'); - } - } - else { - console.log('Error! Asynchronous decoding is disabled'); - } - }; - LZMAHelper.decoder = new utils.LZMA(); - LZMAHelper.enableAsync = false; - LZMAHelper.ENCODE = 1; - LZMAHelper.DECODE = 2; - return LZMAHelper; - })(); - utils.LZMAHelper = LZMAHelper; - })(utils = nid.utils || (nid.utils = {})); -})(nid || (nid = {})); -nid.utils.LZMAHelper.init(); -var nid; -(function (nid) { - var utils; - (function (utils) { - /** - * JavaScript ByteArray - * version : 0.2 - * @author Nidin Vinayakan | nidinthb@gmail.com - */ - var CompressionAlgorithm = (function () { - function CompressionAlgorithm() { - } - CompressionAlgorithm.DEFLATE = "deflate"; - CompressionAlgorithm.LZMA = "lzma"; - CompressionAlgorithm.ZLIB = "zlib"; - return CompressionAlgorithm; - })(); - utils.CompressionAlgorithm = CompressionAlgorithm; - })(utils = nid.utils || (nid.utils = {})); -})(nid || (nid = {})); -var __extends = (this && this.__extends) || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -/// -/// -/*///*/ -/// -/** -* JavaScript ByteArray -* version : 0.2 -* @author Nidin Vinayakan | nidinthb@gmail.com -* -* ActionScript3 ByteArray implementation in JavaScript -* limitation : size of ByteArray cannot be changed -* -*/ -var nid; -(function (nid) { - var utils; - (function (utils) { - var ByteArray = (function (_super) { - __extends(ByteArray, _super); - function ByteArray(buffer, offset, length) { - if (offset === void 0) { offset = 0; } - if (length === void 0) { length = 0; } - _super.call(this, buffer, offset, length); - } - ByteArray.prototype.compress = function (algorithm) { - if (algorithm === void 0) { algorithm = utils.CompressionAlgorithm.LZMA; } - throw "Compression error! " + algorithm + " not implemented"; - if (algorithm == utils.CompressionAlgorithm.LZMA) { - } - else { - throw "Compression error! " + algorithm + " not implemented"; - } - }; - ByteArray.prototype.decompressBuffer = function (algorithm) { - if (algorithm === void 0) { algorithm = utils.CompressionAlgorithm.LZMA; } - if (algorithm == utils.CompressionAlgorithm.LZMA) { - try { - this.buffer = utils.LZMAHelper.decodeBuffer(this.buffer); - } - catch (e) { - throw "Uncompression error! " + algorithm + " not implemented"; - } - } - else if (algorithm == utils.CompressionAlgorithm.ZLIB) { - } - else { - throw "Uncompression error! " + algorithm + " not implemented"; - } - }; - ByteArray.prototype.decompress = function (algorithm) { - if (algorithm === void 0) { algorithm = utils.CompressionAlgorithm.LZMA; } - if (algorithm == utils.CompressionAlgorithm.LZMA) { - try { - this.array = utils.LZMAHelper.decode(this.array); - } - catch (e) { - throw "Uncompression error! " + algorithm + " not implemented"; - } - } - else if (algorithm == utils.CompressionAlgorithm.ZLIB) { - } - else { - throw "Uncompression error! " + algorithm + " not implemented"; - } - }; - ByteArray.prototype.compressAsync = function (algorithm, callback) { - throw "Compression error! " + algorithm + " not implemented"; - if (algorithm == utils.CompressionAlgorithm.LZMA) { - } - else { - throw "Compression error! " + algorithm + " not implemented"; - } - }; - ByteArray.prototype.decompressAsync = function (algorithm, callback) { - if (algorithm === void 0) { algorithm = utils.CompressionAlgorithm.LZMA; } - if (callback === void 0) { callback = null; } - if (algorithm == utils.CompressionAlgorithm.LZMA) { - utils.LZMAHelper.decodeAsync(this.buffer, function (_data) { - this.buffer = _data; - }); - } - else { - throw "Uncompression error! " + algorithm + " not implemented"; - } - }; - ByteArray.prototype.deflate = function () { }; - ByteArray.prototype.inflate = function () { }; - /** - * Reads the number of data bytes, specified by the length parameter, from the byte stream. - * The bytes are read into the ByteArray object specified by the bytes parameter, - * and the bytes are written into the destination ByteArrayBase starting at the _position specified by offset. - * @param bytes The ByteArray object to read data into. - * @param offset The offset (_position) in bytes at which the read data should be written. - * @param length The number of bytes to read. The default value of 0 causes all available data to be read. - */ - ByteArray.prototype.readBytesAsByteArray = function (_bytes, offset, length, createNewBuffer) { - if (_bytes === void 0) { _bytes = null; } - if (offset === void 0) { offset = 0; } - if (length === void 0) { length = 0; } - if (createNewBuffer === void 0) { createNewBuffer = false; } - if (length == 0) { - length = this.bytesAvailable; - } - else if (!this.validate(length)) - return null; - if (createNewBuffer) { - _bytes = _bytes == null ? new ByteArray(new ArrayBuffer(length)) : _bytes; - //This method is expensive - for (var i = 0; i < length; i++) { - _bytes.data.setUint8(i + offset, this.data.getUint8(this.position++)); - } - } - else { - //Offset argument ignored - _bytes = _bytes == null ? new ByteArray(null) : _bytes; - _bytes.dataView = new DataView(this.data.buffer, this.bufferOffset + this.position, length); - this.position += length; - } - return _bytes; - }; - /** - * Reads an object from the byte array, encoded in AMF - * serialized format. - * @return The deserialized object. - */ - ByteArray.prototype.readObject = function () { - //return this.readAmfObject(); - return null; - }; - /** - * Writes an object into the byte array in AMF - * serialized format. - * @param object The object to serialize. - */ - ByteArray.prototype.writeObject = function (value) { - }; - ByteArray.BIG_ENDIAN = "bigEndian"; - ByteArray.LITTLE_ENDIAN = "littleEndian"; - return ByteArray; - })(utils.ByteArrayBase); - utils.ByteArray = ByteArray; - })(utils = nid.utils || (nid.utils = {})); -})(nid || (nid = {})); -//# sourceMappingURL=ByteArray.js.map \ No newline at end of file diff --git a/build/es5/ByteArray.js.map b/build/es5/ByteArray.js.map deleted file mode 100644 index 7e9d90b..0000000 --- a/build/es5/ByteArray.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"ByteArray.js","sourceRoot":"","sources":["../../src/ctypes/UInt64.ts","../../src/ctypes/Int64.ts","../../src/ByteArrayBase.ts","../../src/MEMORY.ts","../../src/lzma/LzmaDecoder.ts","../../src/lzma/OutWindow.ts","../../src/lzma/RangeDecoder.ts","../../src/lzma/BitTreeDecoder.ts","../../src/lzma/LenDecoder.ts","../../src/lzma/LZMA.ts","../../src/LZMAHelper.ts","../../src/CompressionAlgorithm.ts","../../src/ByteArray.ts"],"names":["ctypes","ctypes.UInt64","ctypes.UInt64.constructor","ctypes.UInt64.value","ctypes.Int64","ctypes.Int64.constructor","ctypes.Int64.value","nid","nid.utils","nid.utils.ByteArrayBase","nid.utils.ByteArrayBase.constructor","nid.utils.ByteArrayBase.buffer","nid.utils.ByteArrayBase.dataView","nid.utils.ByteArrayBase.phyPosition","nid.utils.ByteArrayBase.bufferOffset","nid.utils.ByteArrayBase.position","nid.utils.ByteArrayBase.length","nid.utils.ByteArrayBase.bytesAvailable","nid.utils.ByteArrayBase.clear","nid.utils.ByteArrayBase.getArray","nid.utils.ByteArrayBase.setArray","nid.utils.ByteArrayBase.setBuffer","nid.utils.ByteArrayBase.readBoolean","nid.utils.ByteArrayBase.readByte","nid.utils.ByteArrayBase.readBytes","nid.utils.ByteArrayBase.readDouble","nid.utils.ByteArrayBase.readFloat","nid.utils.ByteArrayBase.readInt","nid.utils.ByteArrayBase.readInt64","nid.utils.ByteArrayBase.readMultiByte","nid.utils.ByteArrayBase.readShort","nid.utils.ByteArrayBase.readUnsignedByte","nid.utils.ByteArrayBase.readUnsignedInt","nid.utils.ByteArrayBase.readVariableSizedUnsignedInt","nid.utils.ByteArrayBase.readU16VX","nid.utils.ByteArrayBase.readUnsignedInt64","nid.utils.ByteArrayBase.readUnsignedShort","nid.utils.ByteArrayBase.readUTF","nid.utils.ByteArrayBase.readUTFBytes","nid.utils.ByteArrayBase.readStandardString","nid.utils.ByteArrayBase.readStringTillNull","nid.utils.ByteArrayBase.writeBoolean","nid.utils.ByteArrayBase.writeByte","nid.utils.ByteArrayBase.writeUnsignedByte","nid.utils.ByteArrayBase.writeBytes","nid.utils.ByteArrayBase.writeDouble","nid.utils.ByteArrayBase.writeFloat","nid.utils.ByteArrayBase.writeInt","nid.utils.ByteArrayBase.writeMultiByte","nid.utils.ByteArrayBase.writeShort","nid.utils.ByteArrayBase.writeUnsignedShort","nid.utils.ByteArrayBase.writeUnsignedInt","nid.utils.ByteArrayBase.writeUTF","nid.utils.ByteArrayBase.writeUTFBytes","nid.utils.ByteArrayBase.toString","nid.utils.ByteArrayBase.writeUint8Array","nid.utils.ByteArrayBase.writeUint16Array","nid.utils.ByteArrayBase.writeUint32Array","nid.utils.ByteArrayBase.writeInt8Array","nid.utils.ByteArrayBase.writeInt16Array","nid.utils.ByteArrayBase.writeInt32Array","nid.utils.ByteArrayBase.writeFloat32Array","nid.utils.ByteArrayBase.writeFloat64Array","nid.utils.ByteArrayBase.readUint8Array","nid.utils.ByteArrayBase.readUint16Array","nid.utils.ByteArrayBase.readUint32Array","nid.utils.ByteArrayBase.readInt8Array","nid.utils.ByteArrayBase.readInt16Array","nid.utils.ByteArrayBase.readInt32Array","nid.utils.ByteArrayBase.readFloat32Array","nid.utils.ByteArrayBase.readFloat64Array","nid.utils.ByteArrayBase.validate","nid.utils.ByteArrayBase.validateBuffer","nid.utils.ByteArrayBase.encodeUTF8","nid.utils.ByteArrayBase.decodeUTF8","nid.utils.ByteArrayBase.encoderError","nid.utils.ByteArrayBase.decoderError","nid.utils.ByteArrayBase.inRange","nid.utils.ByteArrayBase.div","nid.utils.ByteArrayBase.stringToCodePoints","nid.utils.MEMORY","nid.utils.MEMORY.constructor","nid.utils.MEMORY.allocateUint8","nid.utils.MEMORY.allocateUint16","nid.utils.MEMORY.allocateUint32","nid.utils.MEMORY.getUint8","nid.utils.MEMORY.getUint16","nid.utils.MEMORY.getUint32","nid.utils.LzmaDecoder","nid.utils.LzmaDecoder.constructor","nid.utils.LzmaDecoder.init","nid.utils.LzmaDecoder.create","nid.utils.LzmaDecoder.createLiterals","nid.utils.LzmaDecoder.initLiterals","nid.utils.LzmaDecoder.decodeLiteral","nid.utils.LzmaDecoder.decodeDistance","nid.utils.LzmaDecoder.initDist","nid.utils.LzmaDecoder.decodeProperties","nid.utils.LzmaDecoder.updateState_Literal","nid.utils.LzmaDecoder.updateState_ShortRep","nid.utils.LzmaDecoder.updateState_Rep","nid.utils.LzmaDecoder.updateState_Match","nid.utils.LzmaDecoder.decode","nid.utils.OutWindow","nid.utils.OutWindow.constructor","nid.utils.OutWindow.create","nid.utils.OutWindow.putByte","nid.utils.OutWindow.getByte","nid.utils.OutWindow.copyMatch","nid.utils.OutWindow.checkDistance","nid.utils.OutWindow.isEmpty","nid.utils.RangeDecoder","nid.utils.RangeDecoder.constructor","nid.utils.RangeDecoder.isFinishedOK","nid.utils.RangeDecoder.init","nid.utils.RangeDecoder.normalize","nid.utils.RangeDecoder.decodeDirectBits","nid.utils.RangeDecoder.decodeBit","nid.utils.BitTreeDecoder","nid.utils.BitTreeDecoder.constructor","nid.utils.BitTreeDecoder.init","nid.utils.BitTreeDecoder.decode","nid.utils.BitTreeDecoder.reverseDecode","nid.utils.BitTreeDecoder.constructArray","nid.utils.LenDecoder","nid.utils.LenDecoder.constructor","nid.utils.LenDecoder.init","nid.utils.LenDecoder.decode","nid.utils.LZMA","nid.utils.LZMA.constructor","nid.utils.LZMA.INIT_PROBS","nid.utils.LZMA.BitTreeReverseDecode","nid.utils.LZMA.decode","nid.utils.LZMAHelper","nid.utils.LZMAHelper.constructor","nid.utils.LZMAHelper.init","nid.utils.LZMAHelper.encode","nid.utils.LZMAHelper.decodeBuffer","nid.utils.LZMAHelper.decode","nid.utils.LZMAHelper.encodeAsync","nid.utils.LZMAHelper.decodeAsync","nid.utils.CompressionAlgorithm","nid.utils.CompressionAlgorithm.constructor","nid.utils.ByteArray","nid.utils.ByteArray.constructor","nid.utils.ByteArray.compress","nid.utils.ByteArray.decompressBuffer","nid.utils.ByteArray.decompress","nid.utils.ByteArray.compressAsync","nid.utils.ByteArray.decompressAsync","nid.utils.ByteArray.deflate","nid.utils.ByteArray.inflate","nid.utils.ByteArray.readBytesAsByteArray","nid.utils.ByteArray.readObject","nid.utils.ByteArray.writeObject"],"mappings":"AAMA,AANA;;;;;GAKG;AACH,IAAO,MAAM,CAkCZ;AAlCD,WAAO,MAAM,EACb,CAAC;IACGA;QAMIC,gBAAYA,GAAYA,EAACA,IAAaA;YAA1BC,mBAAYA,GAAZA,OAAYA;YAACA,oBAAaA,GAAbA,QAAaA;YAClCA,IAAIA,CAACA,GAAGA,GAAMA,GAAGA,CAACA;YAClBA,IAAIA,CAACA,IAAIA,GAAKA,IAAIA,CAACA;QACvBA,CAACA;QACMD,sBAAKA,GAAZA;YAGIE,AADAA,+CAA+CA;gBAC3CA,EAAEA,GAAUA,IAAIA,CAACA,IAAIA,CAACA,QAAQA,CAACA,EAAEA,CAACA,CAACA;YACvCA,IAAIA,GAAGA,GAAUA,CAACA,GAAGA,EAAEA,CAACA,MAAMA,CAACA;YAC/BA,EAAEA,CAAAA,CAACA,GAAGA,GAAGA,CAACA,CAACA,CAAAA,CAACA;gBACRA,GAAGA,CAAAA,CAACA,GAAGA,CAACA,CAACA,GAACA,CAACA,EAACA,CAACA,GAACA,GAAGA,EAACA,CAACA,EAAEA,EAACA,CAACA;oBACnBA,EAAEA,GAAGA,GAAGA,GAACA,EAAEA,CAACA;gBAChBA,CAACA;YACLA,CAACA;YACDA,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A,CAACA;gBAC7BA,OAAOA,CAACA,GAAGA,MAAMA,CAACA,MAAMA,EAAEA,CAACA;oBACvBA,IAAIA,CAACA,GAAGA,MAAMA,CAACA,UAAUA,CAACA,CAACA,CAACA,CAACA;oBAC7BA,EAAEA,CAACA,CAACA,CAACA,IAAIA,CAACA,OAAOA,CAACA,CAACA,EAAEA,MAAMA,EAAEA,MAAMA,CAACA,CAACA,CAACA,CAACA;wBACnCA,GAAGA,CAACA,IAAIA,CAACA,CAACA,CAACA,CAACA;oBAChBA,CAACA;oBAACA,IAAIA,CAACA,EAAEA,CAACA,CAACA,IAAIA,CAACA,OAAOA,CAACA,CAACA,EAAEA,MAAMA,EAAEA,MAAMA,CAACA,CAACA,CAACA,CAACA;wBACzCA,GAAGA,CAACA,IAAIA,CAACA,MAAMA,CAACA,CAACA;oBACrBA,CAACA;oBAACA,IAAIA,CAACA,CAACA;wBACJA,EAAEA,CAACA,CAACA,CAACA,KAAKA,CAACA,GAAGA,CAACA,CAACA,CAACA,CAACA;4BACdA,GAAGA,CAACA,IAAIA,CAACA,MAAMA,CAACA,CAACA;wBACrBA,CAACA;wBAACA,IAAIA,CAACA,CAACA;4BACJA,IAAIA,CAACA,GAAGA,MAAMA,CAACA,UAAUA,CAACA,CAACA,GAAGA,CAACA,CAACA,CAACA;4BACjCA,EAAEA,CAACA,CAACA,IAAIA,CAACA,OAAOA,CAACA,CAACA,EAAEA,MAAMA,EAAEA,MAAMA,CAACA,CAACA,CAACA,CAACA;gCAClCA,IAAIA,CAACA,GAAGA,CAACA,GAAGA,KAAKA,CAACA;gCAClBA,IAAIA,CAACA,GAAGA,CAACA,GAAGA,KAAKA,CAACA;gCAClBA,CAACA,IAAIA,CAACA,CAACA;gCACPA,GAAGA,CAACA,IAAIA,CAACA,OAAOA,GAAGA,CAACA,CAACA,IAAIA,EAAEA,CAACA,GAAGA,CAACA,CAACA,CAACA;4BACtCA,CAACA;4BAACA,IAAIA,CAACA,CAACA;gCACJA,GAAGA,CAAC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,CAACA,GAAGA,CAACA,IAAIA,CAACA,OAAOA,CAACA,GAAGA,CAACA,CAACA;gBAC7BA,MAAMA,CAACA,GAAGA,CAACA,IAAIA,CAACA,SAASA,CAACA,GAAGA,CAACA,CAACA,IAAIA,CAACA,SAASA,CAACA,QAAQA,GAAGA,CAACA,CAACA,CAACA,IAAIA,IAAIA,CAACA,EAAEA,CAACA,GAAGA,CAACA,CAACA,CAACA,IAAIA,IAAIA,CAACA,EAAEA,CAACA,GAAGA,CAACA,MAAMA,CAACA,GAAGA,CAACA,IAAIA,CAACA,SAASA,CAACA,KAAKA,CAACA,CAACA,GAAGA,IAAIA,CAACA,EAAEA,CAACA,CAACA,CAACA;gBAC5IA,IAAIA,WAAWA,GAAUA,CAACA,KAAKA,GAAGA,MAAMA,CAACA,GAAGA,CAACA,IAAIA,CAACA,SAASA,CAACA,CAACA,GAAGA,CAACA,CAACA;gBAElEA,EAAEA,CAACA,CAACA,KAAKA,IAAIA,CAACA,CAACA,CACfA,CAACA;oBACGA,MAAMA,CAACA,GAAGA,CAACA,IAAIA,CAACA,UAAUA,CAACA,GAAGA,IAAIA,CAACA,SAASA,CAACA,OAAOA,CAACA,IAAIA,GAAGA,CAACA,CAACA,CAACA;oBAC/DA,GACAA,CAACA;wBACGA,MAAMA,CAACA,GAAGA,CAACA,IAAIA,CAACA,SAASA,CAACA,GAAGA,CAACA,MAAMA,CAACA,GAAGA,CAACA,IAAIA,CAACA,UAAUA,CAACA,KAAKA,CAACA,CAACA,GAAGA,CAACA,CAACA;wBACrEA,MAAMA,CAACA,GAAGA,CAACA,IAAIA,CAACA,UAAUA,CAACA,KAAKA,CAACA,CAACA;wBAClCA,MAAMA,CAACA,GAAGA,CAACA,IAAIA,CAACA,IAAIA,CAACA,GAAGA,IAAIA,CAACA,QAAQA,CAACA,SAASA,CAACA,IAAIA,CAACA,QAAQA,EAACA,WAAWA,GAAGA,CAACA,CAACA,CAACA,GAAGA,MAAMA,CAACA,GAAGA,CAACA,IAAIA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CAACA,IAAIA,CAACA,IAAIA,CAACA,IAAIA,IAAIA,CAACA,YAAYA,CAACA,aAAaA,CAACA,IAAIA,CAACA,QAAQA,CAACA,CAACA;gBAC5EA,CAACA;gBACDA,MAAMA,CAACA,MAAMA,CAACA,GAAGA,CAACA,IAAIA,CAACA,IAAIA,CAACA,CAACA;YACjCA,CAACA;YACOP,8BAAQA,GAAhBA;gBAEIQ,GAAGA,CAACA,CAACA,GAAGA,CAACA,CAACA,GAAGA,CAACA,EAAEA,CAACA,GAAGA,UAAIA,CAACA,kBAAkBA,EAAEA,CAACA,EAAEA,EAACA,CAACA;oBAC9CA,IAAIA,CAACA,cAAcA,CAACA,CAACA,CAACA,CAACA,IAAIA,EAAEA,CAACA;gBAClCA,CAACA;gBACDA,IAAIA,CAACA,YAAYA,CAACA,IAAIA,EAAEA,CAACA;gBACzBA,UAAIA,CAACA,UAAUA,CAACA,IAAIA,CAACA,WAAWA,CAACA,CAACA;YACtCA,CAACA;YACMR,sCAAgBA,GAAvBA,UAAwBA,UAAqBA;gBAEzCS,IAAIA,IAAIA,GAAGA,IAAIA,UAAUA,CAACA,CAACA,CAACA,CAACA;gBAC7BA,IAAIA,CAACA,CAACA,CAACA,GAAGA,UAAUA,CAACA,CAACA,CAACA,CAACA;gBACxBA,EAAEA,CAACA,CAACA,IAAIA,CAACA,CAACA,CAACA,IAAIA,CAACA,CAACA,GAAGA,CAACA,GAAGA,CAACA,CAACA,CAACA,CAAAA,CAACA;oBACxBA,MAAMA,2BAA2BA,CAACA;gBACtCA,CAACA;gBACDA,IAAIA,CAACA,CAACA,CAACA,GAAGA,IAAIA,CAACA,CAACA,CAACA,GAAGA,CAACA,CAACA;gBACtBA,IAAIA,CAACA,CAACA,CAACA,IAAIA,CAACA,CAACA;gBACbA,IAAIA,CAACA,CAACA,CAACA,GAAGA,IAAIA,CAACA,CAACA,CAACA,GAAGA,CAACA,CAACA;gBACtBA,IAAIA,CAACA,CAACA,CAACA,GAAGA,IAAIA,CAACA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ACA,GAAGA,CAACA,CAACA,CAACA;oBAE9DA,EAAEA,CAACA,CAACA,IAAIA,CAACA,QAAQA,CAACA,SAASA,CAACA,IAAIA,CAACA,OAAOA,EAACA,CAACA,KAAKA,IAAIA,UAAIA,CAACA,cAAcA,CAACA,GAAGA,QAAQA,CAACA,IAAIA,CAACA,CAACA,CACzFA,CAACA;wBACGA,EAAEA,CAACA,CAACA,iBAAiBA,IAAIA,UAAUA,IAAIA,CAACA,CAACA,CAAAA,CAACA;4BACtCA,MAAMA,CAACA,UAAIA,CAACA,cAAcA,CAACA;wBAC/BA,CAACA;wBACDA,IAAIA,CAACA,aAAaA,CAACA,KAAKA,EAAEA,IAAIA,CAACA,CAACA;wBAChCA,KAAKA,GAAGA,IAAIA,CAACA,mBAAmBA,CAACA,KAAKA,CAACA,CAACA;wBACxCA,UAAUA,EAAEA,CAACA;wBACbA,QAAQA,CAACA;oBACbA,CAACA;oBAEDA,IAAIA,GAAGA,CAACA;oBAERA,EAAEA,CAACA,CAACA,IAAIA,CAACA,QAAQA,CAACA,SAASA,CAACA,IAAIA,CAACA,KAAKA,EAACA,KAAKA,CAACA,IAAIA,CAACA,CAACA,CACnDA,CAACA;wBACGA,EAAEA,CAACA,CAACA,iBAAiBA,IAAIA,UAAUA,IAAIA,CAACA,CAACA,CAAAA,CAACA;4BACtCA,MAAMA,CAACA,UAAIA,CAACA,cAAcA,CAACA;wBAC/BA,CAACA;wBACDA,EAAEA,CAACA,CAACA,IAAIA,CAACA,SAASA,CAACA,OAAOA,EAAEA,CAACA,CAAAA,CAACA;4BAC1BA,MAAMA,CAACA,UAAIA,CAACA,cAAcA,CAACA;wBAC/BA,CAACA;wBACDA,EAAEA,CAACA,CAACA,IAAIA,CAACA,QAAQA,CAACA,SAASA,CAACA,IAAIA,CAACA,OAAOA,EAACA,KAAKA,CAACA,IAAIA,CAACA,CAACA,CACrDA,CAACA;4BACGA,EAAEA,CAACA,CAACA,IAAIA,CAACA,QAAQA,CAACA,SAASA,CAACA,IAAIA,CAACA,UAAUA,EAACA,CAACA,KAAKA,IAAIA,UAAIA,CAACA,cAAcA,CAACA,GAAGA,QAAQA,CAACA,IAAIA,CAACA,CAACA,CAC5FA,CAACA;gCACGA,KAAKA,GAAGA,IAAIA,CAACA,oBAAoBA,CAACA,KAAKA,CAACA,CAACA;gCACzCA,IAAIA,CAACA,SAASA,CAACA,OAAOA,CAACA,IAAIA,CAACA,SAASA,CAACA,OAAOA,CAACA,IAAIA,GAAGA,CAACA,CAACA,CAACA,CAACA;gCACzDA,UAAUA,EAAEA,CAACA;gCACbA,QAAQA,CAACA;4BACbA,CAACA;wBACLA,CAACA;wBACDA,IAAIA,CACJA,CAACA;4BACGA,IAAIA,IAAWA,CAACA;4BAChBA,EAAEA,CAACA,CAACA,IAAIA,CAACA,QAAQA,CAACA,SAASA,CAACA,IAAIA,CAACA,OAAOA,EAACA,KAAKA,CAACA,IAAIA,CAACA,CAACA,CAAAA,CAACA;gCAClDA,IAAIA,GAAGA,IAAIA,CAACA;4BAChBA,CAACA;4BACDA,IAAIA,CACJA,CAACA;gCACGA,EAAEA,CAACA,CAACA,IAAIA,CAACA,QAAQA,CAACA,SAASA,CAACA,IAAIA,CAACA,OAAOA,EAACA,KAAKA,CAACA,IAAIA,CAACA,CAACA,CAAAA,CAACA;oCAClDA,IAAIA,GAAGA,IAAIA,CAACA;gCAChBA,CAACA;gCACDA,IAAIA,CACJA,CAACA;oCACGA,IAAIA,GAAGA,IAAIA,CAACA;oCACZA,IAAIA,GAAGA,IAAIA,CAACA;gCAChBA,CAACA;gCACDA,IAAIA,GAAGA,IAAIA,CAACA;4BAChBA,CAACA;4BACDA,IAAIA,GAAGA,IAAIA,CAACA;4BACZA,IAAIA,GAAGA,IAAIA,CAACA;wBAChBA,CAACA;wBACDA,GAAGA,GAAGA,IAAIA,CAACA,aAAaA,CAACA,MAAMA,CAACA,IAAIA,CAACA,QAAQA,EAAEA,QAAQA,CAACA,CAACA;wBACzDA,KAAKA,GAAGA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GAAGA,CAACA,IAAIA,CAACA,GAAGA,CAACA,CAACA,CAACA,KAAKA,EAAEA,CAACA,GAAGA,IAAIA,CAACA,GAAGA,CAACA,CAACA,CAACA,CAACA;gBAEjDA,AADAA,oBAAoBA;gBACpBA,EAAEA,CAACA,CAACA,IAAIA,CAACA,GAAGA,CAACA,CAACA,CAACA,GAAGA,IAAIA,CAACA,GAAGA,CAACA,CAACA,CAACA,CAACA,CAC9BA,CAACA;oBACGA,IAAIA,CAACA,GAAGA,CAACA,CAACA,CAACA,IAAIA,CAACA,CAACA,CAACA,IAAIA,EAAEA,CAACA,GAAGA,IAAIA,CAACA,GAAGA,CAACA,CAACA,CAACA,CAACA,KAAKA,CAACA,CAACA;oBAC/CA,IAAIA,CAACA,GAAGA,CAACA,CAACA,CAACA,GAAGA,IAAIA,CAACA,GAAGA,CAACA,CAACA,CAACA,CAACA;oBAC1BA,IAAIA,CAACA,GAAGA,CAACA,CAACA,CAACA,GAAGA,CAACA,CAACA;gBACpBA,CAACA;gBACDA,IAAIA,CACJA,CAACA;oBAEGA,AADAA,+BAA+BA;oBAC/BA,IAAIA,CAACA,GAAGA,CAACA,CAACA,CAACA,IAAIA,IAAIA,CAACA,GAAGA,CAACA,CAACA,CAACA,KAAKA,CAACA,CAACA;oBACjCA,IAAIA,CAACA,GAAGA,CAACA,CAACA,CAACA,IAAIA,IAAIA,CAACA,GAAGA,CAACA,CAACA,CAACA,CAACA;oBAC3BA,IAAIA,CAACA,GAAGA,CAACA,CAACA,CAACA,IAAIA,IAAIA,CAACA,GAAGA,CAACA,CAACA,CAACA,CAACA;oBAC3BA,IAAIA,CAACA,GAAGA,CAACA,CAACA,CAACA,GAAGA,CAACA,CAACA;gBACpBA,CAACA;gBACDA,IAAIA,CAACA,KAAKA,CAACA,GAAGA,IAAIA,CAACA,GAAGA,CAACA,CAACA,CAACA,CAACA;gBAE1BA,AADAA,mBAAmBA;gBACnBA,EAAEA,CAACA,CAACA,IAAIA,CAACA,GAAGA,CAAC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ACA,MAAMA,CAACA,CAACA;gBACtDA,OAAOA,CAACA,GAAGA,CAACA,UAAUA,EAAEA,IAAIA,CAACA,OAAOA,CAACA,SAASA,CAACA,OAAOA,CAACA,CAACA;gBAExDA,EAAEA,CAACA,CAACA,GAAGA,IAAIA,IAAIA,CAACA,cAAcA,CAACA,CAAAA,CAACA;oBAC5BA,MAAMA,qBAAqBA,CAACA;gBAChCA,CAACA;gBACDA,IAAIA,CAACA,EAAEA,CAACA,CAACA,GAAGA,IAAIA,IAAIA,CAACA,gCAAgCA,CAACA,CAAAA,CAACA;oBACnDA,OAAOA,CAACA,GAAGA,CAACA,6BAA6BA,CAACA,CAACA;gBAC/CA,CAACA;gBACDA,IAAIA,CAACA,EAAEA,CAACA,CAACA,GAAGA,IAAIA,IAAIA,CAACA,6BAA6BA,CAACA,CACnDA,CAACA;oBACGA,EAAEA,CAACA,CAACA,iBAAiBA,CAACA,CACtBA,CAACA;wBACGA,EAAEA,CAACA,CAACA,IAAIA,CAACA,OAAOA,CAACA,SAASA,CAACA,OAAOA,IAAIA,UAAUA,CAACA,CAAAA,CAACA;4BAC9CA,MAAMA,qDAAqDA,CAACA;wBAChEA,CAACA;wBACDA,OAAOA,CAACA,GAAGA,CAACA,WAAWA,CAACA,CAACA;oBAC7BA,CAACA;oBACDA,OAAOA,CAACA,GAAGA,CAACA,0BAA0BA,CAACA,CAACA;gBAC5CA,CAACA;gBACDA,IAAIA,CAAAA,CAACA;oBACDA,MAAMA,gBAAgBA,CAACA;gBAC3BA,CAACA;gBAEDA,OAAOA,CAACA,GAAGA,CAACA,IAAIA,CAACA,CAACA;gBAElBA,EAAEA,CAACA,CAACA,IAAIA,CAACA,OAAOA,CAACA,QAAQA,CAACA,SAASA,CAACA,CACpCA,CAACA;oBACGA,OAAOA,CAACA,GAAGA,CAACA,uCAAuCA,CAACA,CAACA;gBACzDA,CAACA;gBACDA,MAAMA,CAACA,IAAIA,CAACA,OAAOA,CAACA,SAASA,CAACA,SAASA,CAACA;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UA,GAAjBA;gBAECU,AADAA,8BAA8BA;gBAC9BA,MAAMA,CAACA,IAAIA,CAACA;YACPA,CAACA;YAGDV;;;;eAIGA;YACIA,+BAAWA,GAAlBA,UAAmBA,KAAUA;YAE7BW,CAACA;YA9GMX,oBAAUA,GAAUA,WAAWA,CAACA;YAChCA,uBAAaA,GAAUA,cAAcA,CAACA;YA8GpDA,gBAACA;QAADA,CAACA,AAjHDvI,EAA+BA,mBAAaA,EAiH3CA;QAjHYA,eAASA,YAiHrBA,CAAAA;IACFA,CAACA,EArHUD,KAAKA,GAALA,SAAKA,KAALA,SAAKA,QAqHfA;AAADA,CAACA,EArHM,GAAG,KAAH,GAAG,QAqHT"} \ No newline at end of file diff --git a/build/es6/ByteArray.js b/build/es6/ByteArray.js index 662f3b7..3817ba5 100644 --- a/build/es6/ByteArray.js +++ b/build/es6/ByteArray.js @@ -1763,7 +1763,7 @@ var nid; utils.CompressionAlgorithm = CompressionAlgorithm; })(utils = nid.utils || (nid.utils = {})); })(nid || (nid = {})); -/// +/// /// /*///*/ /// diff --git a/gulpfile.js b/gulpfile.js index d7da0c5..c2a3dd0 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -9,7 +9,7 @@ var del = require('del'); var build_path = "build"; var paths = { ts_files: [ - 'src/ByteArray.ts' + 'src/DataArray.ts' ], ts_classes: ['ByteArray'], js_scripts: [build_path+'/**/*.js'] diff --git a/package.json b/package.json index 4a4a14f..218d6b2 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,8 @@ { - "name": "TS-ByteArray", + "name": "DataArray", "version": "1.3.0", - "description": "ActionScript3 ByteArray API for JavaScript", - "main": "src/ByteArray.ts", - "bin": { - "TS-ByteArray": "ByteArrayTest.js" - }, + "description": "Extended ActionScript3 ByteArray API for JavaScript", + "main": "src/nid/utils/DataArray.ts", "directories": { "test": "test" }, @@ -15,22 +12,24 @@ }, "repository": { "type": "git", - "url": "https://github.com/nidin/TS-ByteArray.git" + "url": "https://github.com/nidin/DataArray.git" }, "keywords": [ "javascript", "typescript", + "dataarray", "bytearray" ], "author": "Nidin Vinayakan ", "license": "MIT", "bugs": { - "url": "https://github.com/nidin/TS-ByteArray/issues" + "url": "https://github.com/nidin/DataArray/issues" }, - "homepage": "https://github.com/nidin/TS-ByteArray", + "homepage": "https://github.com/nidin/DataArray", "devDependencies": { "bower":"1.5.3", - "typescript":"1.5.3", + "typescript": "^1.7.5", + "systemjs": "0.19.6", "gulp":"3.9.0", "gulp-shell":"0.4.3", "gulp-uglify":"1.4.1", diff --git a/src/AMFHelper.ts b/src/AMFHelper.ts deleted file mode 100644 index d975303..0000000 --- a/src/AMFHelper.ts +++ /dev/null @@ -1,621 +0,0 @@ -/// -/** -* JavaScript AMF Serializer -* version : 0.1 -* @author Nidin Vinayakan | nidinthb@gmail.com -* -*/ -module nid.utils -{ - - export class AMFHelper - { - /** - * AMF 3 Encoding and Decoding - */ - - // AMF marker constants - private UNDEFINED_TYPE = 0; - private NULL_TYPE = 1; - private FALSE_TYPE = 2; - private TRUE_TYPE = 3; - private INTEGER_TYPE = 4; - private DOUBLE_TYPE = 5; - private STRING_TYPE = 6; - private XML_DOC_TYPE = 7; - private DATE_TYPE = 8; - private ARRAY_TYPE = 9; - private OBJECT_TYPE = 10; - private XML_TYPE = 11; - private BYTE_ARRAY_TYPE = 12; - - // AbstractMessage Serialization Constants - private HAS_NEXT_FLAG = 128; - private BODY_FLAG = 1; - private CLIENT_ID_FLAG = 2; - private DESTINATION_FLAG = 4; - private HEADERS_FLAG = 8; - private MESSAGE_ID_FLAG = 16; - private TIMESTAMP_FLAG = 32; - private TIME_TO_LIVE_FLAG = 64; - private CLIENT_ID_BYTES_FLAG = 1; - private MESSAGE_ID_BYTES_FLAG = 2; - - //AsyncMessage Serialization Constants - private CORRELATION_ID_FLAG = 1; - private CORRELATION_ID_BYTES_FLAG = 2; - - // CommandMessage Serialization Constants - private OPERATION_FLAG = 1; - - private CLASS_ALIAS_REGISTRY = { - "DSK": "flex.messaging.messages.AcknowledgeMessageExt", - "DSA": "flex.messaging.messages.AsyncMessageExt", - "DSC": "flex.messaging.messages.CommandMessageExt" - }; - - private Flex = null; - private initFlex():void - { - // Abstract Message // - this.Flex.AbstractMessage = function() { - this.clientId = null; // object - this.destination = null; // string - this.messageId = null; // string - this.timestamp = null; // number - this.timeToLive = null; // number - - this.headers = null; // Map - this.body = null; // object - - //this.clientIdBytes; // byte array - //this.messageIdBytes; // byte array - }; - - this.Flex.AbstractMessage.prototype = { - - readExternal: function(ba, parser) { - var flagsArray = this.readFlags(ba); - for (var i = 0; i < flagsArray.length; i++) { - var flags = flagsArray[i], - reservedPosition = 0; - console.log(i +'/'+flagsArray.length, flags) - if (i == 0) { - if ((flags & this.BODY_FLAG) != 0) this.readExternalBody(ba, parser); - if ((flags & this.CLIENT_ID_FLAG) != 0) this.clientId = parser.readData(ba); - if ((flags & this.DESTINATION_FLAG) != 0) this.destination = parser.readData(ba); - if ((flags & this.HEADERS_FLAG) != 0) this.headers = parser.readData(ba); - if ((flags & this.MESSAGE_ID_FLAG) != 0) this.messageId = parser.readData(ba); - if ((flags & this.TIMESTAMP_FLAG) != 0) this.timestamp = parser.readData(ba); - if ((flags & this.TIME_TO_LIVE_FLAG) != 0) this.timeToLive = parser.readData(ba); - reservedPosition = 7; - } else if (i == 1) { - if ((flags & this.CLIENT_ID_BYTES_FLAG) != 0) { - var clientIdBytes = parser.readData(ba); - this.clientId = this.UUIDUtils.fromByteArray(clientIdBytes); - } - - if ((flags & this.MESSAGE_ID_BYTES_FLAG) != 0) { - var messageIdBytes = parser.readData(ba); - this.messageId = this.UUIDUtils.fromByteArray(messageIdBytes); - } - - reservedPosition = 2; - } - - // For forwards compatibility, read in any other flagged objects to - // preserve the integrity of the input stream... - if ((flags >> reservedPosition) != 0) { - for (var j = reservedPosition; j < 6; j++) { - if (((flags >> j) & 1) != 0) parser.readData(ba); - } - } - } - - return this; - }, - - readExternalBody: function(ba, parser) { - this.body = parser.readData(ba); - }, - - readFlags: function(ba) { - var hasNextFlag = true, - flagsArray = [], - i = 0; - - while (hasNextFlag) { - var flags = ba.readUnsignedByte(); - /*if (i == flagsArray.length) { - short[] tempArray = new short[i*2]; - System.arraycopy(flagsArray, 0, tempArray, 0, flagsArray.length); - flagsArray = tempArray; - }*/ - - flagsArray[i] = flags; - hasNextFlag = ((flags & this.HAS_NEXT_FLAG) != 0) ? true : false; - i++; - } - - return flagsArray; - } - }; - - // flex.messaging.messages.AsyncMessage // - this.Flex.AsyncMessage = function() { - this.correlationId = null; // string - //var correlationIdBytes; // byte array - }; - this.Flex.AsyncMessage.prototype = new this.Flex.AbstractMessage(); - this.Flex.AsyncMessage.constructor = this.Flex.AsyncMessage; - - this.Flex.AsyncMessage.prototype.readExternal = function(ba, parser) { - this.Flex.AbstractMessage.prototype.readExternal.call(this, ba, parser); - - var flagsArray = this.readFlags(ba); - for (var i = 0; i < flagsArray.length; i++) { - var flags = flagsArray[i], - reservedPosition = 0; - - if (i == 0) { - if ((flags & this.CORRELATION_ID_FLAG) != 0) this.correlationId = parser.readData(ba); - - if ((flags & this.CORRELATION_ID_BYTES_FLAG) != 0) { - var correlationIdBytes = parser.readData(ba); - this.correlationId = this.UUIDUtils.fromByteArray(correlationIdBytes); - } - - reservedPosition = 2; - } - - // For forwards compatibility, read in any other flagged objects - // to preserve the integrity of the input stream... - if ((flags >> reservedPosition) != 0) { - for (var j = reservedPosition; j < 6; ++j) { - if (((flags >> j) & 1) != 0) parser.readData(ba); - } - } - } - - return this; - }; - - // DSA - flex.messaging.messages.AsyncMessageExt // - this.Flex.AsyncMessageExt = function() { }; - this.Flex.AsyncMessageExt.prototype = new this.Flex.AsyncMessage(); - this.Flex.AsyncMessageExt.constructor = this.Flex.AsyncMessageExt; - - // flex.messaging.messages.AcknowledgeMessage // - this.Flex.AcknowledgeMessage = function() { }; - this.Flex.AcknowledgeMessage.prototype = new this.Flex.AsyncMessage(); - this.Flex.AcknowledgeMessage.constructor = this.Flex.AcknowledgeMessage; - - this.Flex.AcknowledgeMessage.prototype.readExternal = function(ba, parser) { - this.Flex.AsyncMessage.prototype.readExternal.call(this, ba, parser); - - var flagsArray = this.readFlags(ba); - for (var i = 0; i < flagsArray.length; ++i) { - var flags = flagsArray[i], - reservedPosition = 0; - - // For forwards compatibility, read in any other flagged objects - // to preserve the integrity of the input stream... - if ((flags >> reservedPosition) != 0) { - for (var j = reservedPosition; j < 6; ++j) { - if (((flags >> j) & 1) != 0) parser.readData(ba); - } - } - } - - return this; - }; - - // DSK - flex.messaging.messages.AcknowledgeMessageExt // - this.Flex.AcknowledgeMessageExt = function() { }; - this.Flex.AcknowledgeMessageExt.prototype = new this.Flex.AcknowledgeMessage(); - this.Flex.AcknowledgeMessageExt.constructor = this.Flex.AcknowledgeMessageExt; - - // flex.messaging.messages.CommandMessage // - this.Flex.CommandMessage = function() { - this.operation = 1000; - this.operationName = "unknown"; - }; - this.Flex.CommandMessage.prototype = new this.Flex.AsyncMessage(); - this.Flex.CommandMessage.constructor = this.Flex.CommandMessage; - - this.Flex.CommandMessage.prototype.readExternal = function(ba, parser) { - this.Flex.AsyncMessage.prototype.readExternal.call(this, ba, parser); - - var flagsArray = this.readFlags(ba); - for (var i = 0; i < flagsArray.length; ++i) { - var flags = flagsArray[i], - reservedPosition = 0, - operationNames = [ - "subscribe", "unsubscribe", "poll", "unused3", "client_sync", "client_ping", - "unused6", "cluster_request", "login", "logout", "subscription_invalidate", - "multi_subscribe", "disconnect", "trigger_connect" - ]; - - if (i == 0) { - if ((flags & this.OPERATION_FLAG) != 0) { - this.operation = parser.readData(ba); - if (this.operation < 0 || this.operation >= operationNames.length) { - this.operationName = "invalid." + this.operation + ""; - } else { - this.operationName = operationNames[this.operation]; - } - } - reservedPosition = 1; - } - - // For forwards compatibility, read in any other flagged objects - // to preserve the integrity of the input stream... - if ((flags >> reservedPosition) != 0) { - for (var j = reservedPosition; j < 6; ++j) { - if (((flags >> j) & 1) != 0) parser.readData(ba); - } - } - } - - return this; - }; - - // DSC - flex.messaging.messages.CommandMessageExt // - this.Flex.CommandMessageExt = function() { }; - this.Flex.CommandMessageExt.prototype = new this.Flex.CommandMessage(); - this.Flex.CommandMessageExt.constructor = this.Flex.CommandMessageExt; - - // flex.messaging.messages.ErrorMessage // - this.Flex.ErrorMessage = function() { - this.faultCode = ''; - this.faultString = ''; - this.faultDetail = ''; - this.rootCause; - this.extendedData; - }; - this.Flex.ErrorMessage.prototype = new this.Flex.AcknowledgeMessage(); - this.Flex.ErrorMessage.constructor = this.Flex.ErrorMessage; - - // flex.messaging.messages.RPCPMessage // - this.Flex.RPCPMessage = function() { - this.remoteUsername = ''; - this.remotePassword = ''; - }; - this.Flex.RPCPMessage.prototype = new this.Flex.AbstractMessage(); - this.Flex.RPCPMessage.constructor = this.Flex.RPCPMessage; - - // flex.messaging.messages.HTTPMessage // - this.Flex.HTTPMessage = function() { - this.contentType = ''; - this.method = ''; - this.url = ''; - this.httpHeaders = {}; - this.recordHeaders = false; - }; - this.Flex.HTTPMessage.prototype = new this.Flex.RPCPMessage(); - this.Flex.HTTPMessage.constructor = this.Flex.HTTPMessage; - - // flex.messaging.messages.RemotingMessage // - this.Flex.RemotingMessage = function() { - this.operation = ''; - this.source = ''; - this.parameters = []; - this.parameterList = []; - }; - this.Flex.RemotingMessage.prototype = new this.Flex.RPCPMessage(); - this.Flex.RemotingMessage.constructor = this.Flex.RemotingMessage; - - // flex.messaging.messages.SOAPMessage // - this.Flex.SOAPMessage = function() { - this.remoteUsername = ''; - this.remotePassword = ''; - }; - this.Flex.SOAPMessage.prototype = new this.Flex.HTTPMessage(); - this.Flex.SOAPMessage.constructor = this.Flex.SOAPMessage; - - // flex.messaging.io.ArrayCollection // - this.Flex.ArrayCollection = function() { - this.source = null; - }; - this.Flex.ArrayCollection.prototype.readExternal = function(ba, parser) { - this.source = parser.readData(ba); - return this; - }; - - // Array List // - this.Flex.ArrayList = function() { }; - this.Flex.ArrayList.prototype = new this.Flex.ArrayCollection(); - this.Flex.ArrayList.constructor = this.Flex.ArrayList; - - // flex.messaging.io.ObjectProxy // - this.Flex.ObjectProxy = function() { }; - this.Flex.ObjectProxy.prototype.readExternal = function(ba, parser) { - var obj = parser.readData(ba); - for (var i in obj) { - this[i] = obj[i]; - } - return this; - }; - - // flex.messaging.io.ManagedObjectProxy // - this.Flex.ManagedObjectProxy = function() { }; - this.Flex.ManagedObjectProxy.prototype = new this.Flex.ObjectProxy(); - this.Flex.ManagedObjectProxy.constructor = this.Flex.ManagedObjectProxy; - - // flex.messaging.io.SerializationProxy // - this.Flex.SerializationProxy = function() { - this.defaultInstance = null; - }; - - this.Flex.SerializationProxy.prototype.readExternal = function(ba, parser) { - /*var saveObjectTable = null; - var saveTraitsTable = null; - var saveStringTable = null; - var in3 = null; - - if (ba instanceof Amf3Input) in3 = ba;*/ - - try { - /*if (in3 != null) { - saveObjectTable = in3.saveObjectTable(); - saveTraitsTable = in3.saveTraitsTable(); - saveStringTable = in3.saveStringTable(); - }*/ - - this.defaultInstance = parser.readData(ba); - } finally { - /*if (in3 != null) { - in3.restoreObjectTable(saveObjectTable); - in3.restoreTraitsTable(saveTraitsTable); - in3.restoreStringTable(saveStringTable); - }*/ - } - - return this; - }; - } - - private readStringCache:Array = []; - private readTraitsCache:Array = []; - private readObjectCache:Array = []; - - private serialize():ArrayBuffer - { - return null; - } - private deserialize():any - { - } - private readAmfData():any - { - if(this.Flex == null){ - this.initFlex(); - } - var type = this.readByte(); - switch(type) { - case this.UNDEFINED_TYPE : return undefined; - case this.NULL_TYPE : return null; - case this.FALSE_TYPE : return false; - case this.TRUE_TYPE : return true; - case this.INTEGER_TYPE : return this.readInt(); - case this.DOUBLE_TYPE : return this.readDouble(); - case this.STRING_TYPE : return this.readString(); - case this.XML_DOC_TYPE : return this.readXMLDoc(); - case this.DATE_TYPE : return this.readDate(); - case this.ARRAY_TYPE : return this.readArray(); - case this.OBJECT_TYPE : return this.readAmfObject(); - case this.XML_TYPE : return this.readXML(); - case this.BYTE_ARRAY_TYPE : return this.readByteArray(); - default: throw { - name:"Error", - message:"AMF3::readAmfData - Error : Undefined AMF3 type encountered '" + type + "'", - errorID:0 - }; - } - } - - private getStringReference(index):string { - if (index >= this.readStringCache.length) { - console.log("AMF3::getStringReference - Error : Undefined string reference '" + index + "'"); - return null; - } - return this.readStringCache[index]; - } - private getTraitReference(index):Object { - if (index >= this.readTraitsCache.length) { - console.log("AMF3::getTraitReference - Error : Undefined trait reference '" + index + "'"); - return null; - } - return this.readTraitsCache[index]; - } - private getObjectReference(index):Object { - if (index >= this.readObjectCache.length) { - console.log("AMF3::getObjectReference - Error : Undefined object reference '" + index + "'"); - return null; - } - return this.readObjectCache[index]; - } - private readU29():number - { - var result = 0; - // Each byte must be treated as unsigned - var b = this.readUnsignedByte(); - - if (b < 128) return b; - - result = (b & 0x7F) << 7; - b = this.readUnsignedByte(); - - if (b < 128) return (result | b); - - result = (result | (b & 0x7F)) << 7; - b = this.readUnsignedByte(); - - if (b < 128) return (result | b); - - result = (result | (b & 0x7F)) << 8; - b = this.readUnsignedByte(); - - return (result | b); - } - private readI29():number - { - var result = this.readU29(); - // Symmetric with writing an integer to fix sign bits for negative values... - result = (result << 3) >> 3; - return result; - } - private readString():string { - var refIndex = this.readU29(); - if ((refIndex & 1) == 0) return this.getStringReference(refIndex >> 1); - - // writeString() special cases the empty string - // to avoid creating a reference. - var len = refIndex >> 1; - var str = ""; - if (len > 0) { - str = this.readUTFBytes(len); - this.readStringCache.push(str); - } - return str; - } - private readXMLDoc() { - var index = this.readU29(); - if((index & 1) == 0) return this.getObjectReference(index >> 1); - - //var xmldoc = new XML(this.readUTFBytes(index >> 1)); - var xmldoc = this.readUTFBytes(index >> 1); - this.readObjectCache.push(xmldoc); - return xmldoc; - } - private readDate() { - var index = this.readU29(); - if ((index & 1) == 0) return this.getObjectReference(index >> 1); - - var d = new Date(this.readDouble()); - this.readObjectCache.push(d); - return d; - } - private readArray() { - var index = this.readU29(); - if ((index & 1) == 0) return this.getObjectReference(index >> 1); - - var arr = []; - this.readObjectCache.push(arr); - - // Associative values - var strKey = this.readString(); - while(strKey != "") { - arr[strKey] = this.readAmfData(); - strKey = this.readString(); - } - - // Strict values - var l = (index >> 1); - for(var i = 0; i < l; i++) { - arr[i] = this.readAmfData(); - } - - return arr; - } - private readAmfObject() { - var index = this.readU29(); - if ((index & 1) == 0) return this.getObjectReference(index >> 1); - - // Read traits - var traits; - if ((index & 3) == 1) { - traits = this.getTraitReference(index >> 2); - } else { - var isExternalizable:boolean = ((index & 4) == 4); - var isDynamic:boolean = ((index & 8) == 8); - var className:string = this.readString(); - - var classMemberCount:number = (index >> 4); /* uint29 */ - var classMembers:Array = []; - for(var i = 0; i < classMemberCount; ++i) { - classMembers.push(this.readString()); - } - if (className.length == 0) className = 'Object'; - traits = { type:className, members:classMembers, count:classMemberCount, externalizable:isExternalizable, dynamic:isDynamic }; - this.readTraitsCache.push(traits); - } - - // Check for any registered class aliases - var aliasedClass = this.CLASS_ALIAS_REGISTRY[traits.type]; - if (aliasedClass != null) traits.type = aliasedClass; - - var obj = {}; - - //Add to references as circular references may search for this object - this.readObjectCache.push(obj); - - if (traits.externalizable) { - // Read Externalizable - try { - if (traits.type.indexOf("flex.") == 0) { - // Try to get a class - var classParts = traits.type.split("."); - var unqualifiedClassName = classParts[(classParts.length - 1)]; - if (unqualifiedClassName && this.Flex[unqualifiedClassName]) { - var flexParser = new this.Flex[unqualifiedClassName](); - obj = flexParser.readExternal(this, this); - } else { - obj = this.readAmfData(); - } - } - } catch (e) { - console.log("AMF3::readObject - Error : Unable to read externalizable data type '" + traits.type + "' | " + e); - obj = "Unable to read externalizable data type '" + traits.type + "'"; - } - } else { - var l = traits.members.length; - var key; - - for(var j = 0; j < l; ++j) { - var val = this.readAmfData(); - key = traits.members[j]; - obj[key] = val; - } - - if(traits.dynamic) { - key = this.readString(); - while(key != "") { - var value = this.readAmfData(); - obj[key] = value; - key = this.readString(); - } - } - } - - if(traits) obj.__traits = traits; - - return obj; - } - private readXML() { - var index = this.readU29(); - if((index & 1) == 0) return this.getObjectReference(index >> 1); - - //var xml = new XML(this.readUTFBytes(index >> 1)); - var xml = this.readUTFBytes(index >> 1); - this.readObjectCache.push(xml); - return xml; - } - private readByteArray() { - var index = this.readU29(); - if ((index & 1) == 0) return this.getObjectReference(index >> 1); - - var len = (index >> 1); - //var ba2 = new ByteArray(); - var ba2 = new ByteArray(new ArrayBuffer(len)); - /*while(len--) { - var b = this.readUnsignedByte().toString(16).toUpperCase(); - if (b.length < 2) b = '0' + b; - ba2.push('0x' + b); - }*/ - this.readBytes(ba2, 0, len); - this.readObjectCache.push(ba2); - return ba2; - } - } -} diff --git a/src/BitArray.ts b/src/BitArray.ts deleted file mode 100644 index 7f2b929..0000000 --- a/src/BitArray.ts +++ /dev/null @@ -1,99 +0,0 @@ -/// -/** - * JavaScript BitArray - * version : 0.2 - * @author Nidin Vinayakan | nidinthb@gmail.com - * - * Utility to read bits from ByteArray - * - */ -module nid.utils -{ - export class BitArray extends ByteArrayBase - { - private bitsPending:number = 0; - constructor(buffer?:ArrayBuffer){ - super(buffer); - } - public readBits(bits:number, bitBuffer:number = 0):number { - if (bits == 0) { return bitBuffer; } - var partial:number; - var bitsConsumed:number; - if (this.bitsPending > 0) { - var _byte:number = this[this.position - 1] & (0xff >> (8 - this.bitsPending)); - bitsConsumed = Math.min(this.bitsPending, bits); - this.bitsPending -= bitsConsumed; - partial = _byte >> this.bitsPending; - } else { - bitsConsumed = Math.min(8, bits); - this.bitsPending = 8 - bitsConsumed; - partial = this.readUnsignedByte() >> this.bitsPending; - } - bits -= bitsConsumed; - bitBuffer = (bitBuffer << bitsConsumed) | partial; - return (bits > 0) ? this.readBits(bits, bitBuffer) : bitBuffer; - } - - public writeBits(bits:number, value:number) { - if (bits == 0) { return; } - value &= (0xffffffff >>> (32 - bits)); - var bitsConsumed:number; - if (this.bitsPending > 0) { - if (this.bitsPending > bits) { - this[this.position - 1] |= value << (this.bitsPending - bits); - bitsConsumed = bits; - this.bitsPending -= bits; - } else if (this.bitsPending == bits) { - this[this.position - 1] |= value; - bitsConsumed = bits; - this.bitsPending = 0; - } else { - this[this.position - 1] |= value >> (bits - this.bitsPending); - bitsConsumed = this.bitsPending; - this.bitsPending = 0; - } - } else { - bitsConsumed = Math.min(8, bits); - this.bitsPending = 8 - bitsConsumed; - this.writeByte((value >> (bits - bitsConsumed)) << this.bitsPending); - } - bits -= bitsConsumed; - if (bits > 0) { - this.writeBits(bits, value); - } - } - - public resetBitsPending() { - this.bitsPending = 0; - } - - public calculateMaxBits(signed:boolean, values:Array):number { - var b:number = 0; - var vmax:number = -2147483648//int.MIN_VALUE; - if(!signed) { - for(var usvalue in values) { - b |= usvalue; - } - } else { - for(var svalue in values) { - if(svalue >= 0) { - b |= svalue; - } else { - b |= ~svalue << 1; - } - if(vmax < svalue) { - vmax = svalue; - } - } - } - var bits:number = 0; - if(b > 0) { - bits = b.toString(2).length; - if(signed && vmax > 0 && vmax.toString(2).length >= bits) { - bits++; - } - } - return bits; - } - } -} diff --git a/src/ByteArray.ts b/src/ByteArray.ts deleted file mode 100644 index c1368e7..0000000 --- a/src/ByteArray.ts +++ /dev/null @@ -1,131 +0,0 @@ -/// -/// -/*///*/ -/// -/** -* JavaScript ByteArray -* version : 0.2 -* @author Nidin Vinayakan | nidinthb@gmail.com -* -* ActionScript3 ByteArray implementation in JavaScript -* limitation : size of ByteArray cannot be changed -* -*/ -module nid.utils -{ - - export class ByteArray extends ByteArrayBase - { - static BIG_ENDIAN:string = "bigEndian"; - static LITTLE_ENDIAN:string = "littleEndian"; - - constructor(buffer?:ArrayBuffer,offset:number=0,length:number=0){ - - super(buffer,offset,length); - } - public compress(algorithm:string=CompressionAlgorithm.LZMA) : void{ - throw "Compression error! "+algorithm+" not implemented"; - if(algorithm == CompressionAlgorithm.LZMA) { - - }else{ - throw "Compression error! "+algorithm+" not implemented"; - } - } - public decompressBuffer(algorithm:string=CompressionAlgorithm.LZMA) : void{ - if(algorithm == CompressionAlgorithm.LZMA) { - try { - this.buffer = LZMAHelper.decodeBuffer(this.buffer); - } catch (e) { - throw "Uncompression error! "+algorithm+" not implemented"; - } - }else if(algorithm == CompressionAlgorithm.ZLIB){ - /*this.buffer = ZLIBHelper.decodeBuffer(this.buffer);*/ - }else{ - throw "Uncompression error! "+algorithm+" not implemented"; - } - } - public decompress(algorithm:string=CompressionAlgorithm.LZMA) : void{ - if(algorithm == CompressionAlgorithm.LZMA) { - try { - this.array = LZMAHelper.decode(this.array); - } catch (e) { - throw "Uncompression error! "+algorithm+" not implemented"; - } - }else if(algorithm == CompressionAlgorithm.ZLIB){ - /*this.array = ZLIBHelper.decode(this.array);*/ - }else{ - throw "Uncompression error! "+algorithm+" not implemented"; - } - } - public compressAsync(algorithm:string,callback) : void{ - throw "Compression error! "+algorithm+" not implemented"; - if(algorithm == CompressionAlgorithm.LZMA) { - - }else{ - throw "Compression error! "+algorithm+" not implemented"; - } - } - public decompressAsync(algorithm:string=CompressionAlgorithm.LZMA,callback=null) : void{ - if(algorithm == CompressionAlgorithm.LZMA){ - LZMAHelper.decodeAsync(this.buffer,function(_data){ - this.buffer = _data; - }) - }else{ - throw "Uncompression error! "+algorithm+" not implemented"; - } - } - public deflate():void{} - public inflate(): void{} - - /** - * Reads the number of data bytes, specified by the length parameter, from the byte stream. - * The bytes are read into the ByteArray object specified by the bytes parameter, - * and the bytes are written into the destination ByteArrayBase starting at the _position specified by offset. - * @param bytes The ByteArray object to read data into. - * @param offset The offset (_position) in bytes at which the read data should be written. - * @param length The number of bytes to read. The default value of 0 causes all available data to be read. - */ - - public readBytesAsByteArray(_bytes:ByteArray=null, offset:number= 0, length:number= 0,createNewBuffer:boolean=false): ByteArray{ - if(length == 0){ - length = this.bytesAvailable; - } - else if (!this.validate(length)) return null; - - if(createNewBuffer){ - _bytes = _bytes == null?new ByteArray(new ArrayBuffer(length)):_bytes; - //This method is expensive - for(var i=0; i < length;i++){ - _bytes.data.setUint8(i+offset,this.data.getUint8(this.position++)); - } - }else{ - //Offset argument ignored - _bytes = _bytes == null?new ByteArray(null):_bytes; - _bytes.dataView = new DataView(this.data.buffer,this.bufferOffset+this.position,length); - this.position += length; - } - - return _bytes; - } - - /** - * Reads an object from the byte array, encoded in AMF - * serialized format. - * @return The deserialized object. - */ - public readObject():any{ - //return this.readAmfObject(); - return null; - } - - - /** - * Writes an object into the byte array in AMF - * serialized format. - * @param object The object to serialize. - */ - public writeObject(value: any): void { - - } - } -} diff --git a/src/ByteArrayBase.ts b/src/ByteArrayBase.ts deleted file mode 100644 index 01d8b9f..0000000 --- a/src/ByteArrayBase.ts +++ /dev/null @@ -1,1070 +0,0 @@ -/// -/** -* JavaScript ByteArrayBase -* version : 0.2 -* @author Nidin Vinayakan | nidinthb@gmail.com -* -* ActionScript3 ByteArrayBase implementation in JavaScript -* limitation : size of ByteArrayBase cannot be changed -* -*/ -module nid.utils -{ - import UInt64 = ctypes.UInt64; - import Int64 = ctypes.Int64; - - export class ByteArrayBase - { - static BIG_ENDIAN:string = "bigEndian"; - static LITTLE_ENDIAN:string = "littleEndian"; - - static SIZE_OF_BOOLEAN: number = 1; - static SIZE_OF_INT8: number = 1; - static SIZE_OF_INT16: number = 2; - static SIZE_OF_INT32: number = 4; - static SIZE_OF_INT64: number = 8; - static SIZE_OF_UINT8: number = 1; - static SIZE_OF_UINT16: number = 2; - static SIZE_OF_UINT32: number = 4; - static SIZE_OF_UINT64: number = 8; - static SIZE_OF_FLOAT32: number = 4; - static SIZE_OF_FLOAT64: number = 8; - - private BUFFER_EXT_SIZE: number = 1024;//Buffer expansion size - - public array:Uint8Array = null; - public data:DataView; - private _position: number; - public write_position: number; - public endian: string; - - constructor(buffer?:ArrayBuffer,offset:number=0,length:number=0){ - - if (buffer == undefined) { - buffer = new ArrayBuffer(this.BUFFER_EXT_SIZE); - this.write_position = 0; - } - else if (buffer == null) { - this.write_position = 0; - } else { - this.write_position = length>0?length:buffer.byteLength; - } - if(buffer){ - this.data = new DataView(buffer,offset,length>0?length:buffer.byteLength); - } - this._position = 0; - this.endian = ByteArrayBase.BIG_ENDIAN; - } - - // getter setter - get buffer(): ArrayBuffer { - return this.data.buffer; - } - set buffer(value: ArrayBuffer) { - this.data = new DataView(value); - } - get dataView(): DataView { - return this.data; - } - set dataView(value: DataView) { - this.data = value; - this.write_position = value.byteLength; - } - get phyPosition(): number { - return this._position + this.data.byteOffset; - } - get bufferOffset(): number { - return this.data.byteOffset; - } - get position(): number { - return this._position; - } - set position(value:number) { - if(this._position < value){ - if(!this.validate(this._position-value)){ - return; - } - } - this._position = value; - this.write_position = value > this.write_position ? value : this.write_position; - } - get length(): number { - return this.write_position; - } - set length(value: number) { - this.validateBuffer(value); - } - - get bytesAvailable():number { - return this.data.byteLength - this._position; - } - //end - public clear():void{ - this._position=0; - } - public getArray():Uint8Array{ - if(this.array == null){ - this.array = new Uint8Array(this.data.buffer,this.data.byteOffset,this.data.byteLength); - } - return this.array; - } - public setArray(array:Uint8Array):void{ - this.array = array; - this.setBuffer(array.buffer, array.byteOffset, array.byteLength); - } - public setBuffer(buffer:ArrayBuffer, offset:number=0, length:number=0){ - if(buffer){ - this.data = new DataView(buffer,offset,length>0?length:buffer.byteLength); - this.write_position = length>0?length:buffer.byteLength; - }else{ - this.write_position = 0; - } - this._position = 0; - } - /** - * Reads a Boolean value from the byte stream. A single byte is read, - * and true is returned if the byte is nonzero, - * false otherwise. - * @return Returns true if the byte is nonzero, false otherwise. - */ - public readBoolean(): boolean{ - if (!this.validate(ByteArrayBase.SIZE_OF_BOOLEAN)) return null; - - return this.data.getUint8(this.position++) != 0; - } - - /** - * Reads a signed byte from the byte stream. - * The returned value is in the range -128 to 127. - * @return An integer between -128 and 127. - */ - public readByte(): number{ - if (!this.validate(ByteArrayBase.SIZE_OF_INT8)) return null; - - return this.data.getInt8(this.position++); - } - - /** - * Reads the number of data bytes, specified by the length parameter, from the byte stream. - * The bytes are read into the ByteArrayBase object specified by the bytes parameter, - * and the bytes are written into the destination ByteArrayBase starting at the _position specified by offset. - * @param bytes The ByteArrayBase object to read data into. - * @param offset The offset (_position) in bytes at which the read data should be written. - * @param length The number of bytes to read. The default value of 0 causes all available data to be read. - */ - public readBytes(_bytes:ByteArrayBase=null, offset:number= 0, length:number= 0,createNewBuffer:boolean=false): ByteArrayBase{ - if(length == 0){ - length = this.bytesAvailable; - } - else if (!this.validate(length)) return null; - - if(createNewBuffer){ - _bytes = _bytes == null?new ByteArrayBase(new ArrayBuffer(length)):_bytes; - //This method is expensive - for(var i=0; i < length;i++){ - _bytes.data.setUint8(i+offset,this.data.getUint8(this.position++)); - } - }else{ - //Offset argument ignored - _bytes = _bytes == null?new ByteArrayBase(null):_bytes; - _bytes.dataView = new DataView(this.data.buffer,this.bufferOffset+this.position,length); - this.position += length; - } - - return _bytes; - } - - /** - * Reads an IEEE 754 double-precision (64-bit) floating-point number from the byte stream. - * @return A double-precision (64-bit) floating-point number. - */ - public readDouble(): number{ - if (!this.validate(ByteArrayBase.SIZE_OF_FLOAT64)) return null; - - var value:number = this.data.getFloat64(this.position, this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_FLOAT64; - return value; - } - - /** - * Reads an IEEE 754 single-precision (32-bit) floating-point number from the byte stream. - * @return A single-precision (32-bit) floating-point number. - */ - public readFloat(): number{ - if (!this.validate(ByteArrayBase.SIZE_OF_FLOAT32)) return null; - - var value: number = this.data.getFloat32(this.position, this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_FLOAT32; - return value; - } - - /** - * Reads a signed 32-bit integer from the byte stream. - * - * The returned value is in the range -2147483648 to 2147483647. - * @return A 32-bit signed integer between -2147483648 and 2147483647. - */ - public readInt(): number{ - if (!this.validate(ByteArrayBase.SIZE_OF_INT32)) return null; - - var value = this.data.getInt32(this.position,this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_INT32; - return value; - } - /** - * Reads a signed 64-bit integer from the byte stream. - * - * The returned value is in the range −(2^63) to 2^63 − 1 - * @return A 64-bit signed integer between −(2^63) to 2^63 − 1 - */ - public readInt64():Int64{ - if (!this.validate(ByteArrayBase.SIZE_OF_UINT32)) return null; - - var low = this.data.getInt32(this.position,this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_INT32; - var high = this.data.getInt32(this.position,this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_INT32; - return new Int64(low,high); - } - - /** - * Reads a multibyte string of specified length from the byte stream using the - * specified character set. - * @param length The number of bytes from the byte stream to read. - * @param charSet The string denoting the character set to use to interpret the bytes. - * Possible character set strings include "shift-jis", "cn-gb", - * "iso-8859-1", and others. - * For a complete list, see Supported Character Sets. - * Note: If the value for the charSet parameter - * is not recognized by the current system, the application uses the system's default - * code page as the character set. For example, a value for the charSet parameter, - * as in myTest.readMultiByte(22, "iso-8859-01") that uses 01 instead of - * 1 might work on your development system, but not on another system. - * On the other system, the application will use the system's default code page. - * @return UTF-8 encoded string. - */ - public readMultiByte(length: number, charSet?: string): string{ - if (!this.validate(length)) return null; - - return ""; - } - - /** - * Reads a signed 16-bit integer from the byte stream. - * - * The returned value is in the range -32768 to 32767. - * @return A 16-bit signed integer between -32768 and 32767. - */ - public readShort(): number{ - if (!this.validate(ByteArrayBase.SIZE_OF_INT16)) return null; - - var value = this.data.getInt16(this.position, this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_INT16; - return value; - } - - /** - * Reads an unsigned byte from the byte stream. - * - * The returned value is in the range 0 to 255. - * @return A 32-bit unsigned integer between 0 and 255. - */ - public readUnsignedByte(): number{ - if (!this.validate(ByteArrayBase.SIZE_OF_UINT8)) return null; - - return this.data.getUint8(this.position++); - } - - /** - * Reads an unsigned 32-bit integer from the byte stream. - * - * The returned value is in the range 0 to 4294967295. - * @return A 32-bit unsigned integer between 0 and 4294967295. - */ - public readUnsignedInt():number{ - if (!this.validate(ByteArrayBase.SIZE_OF_UINT32)) return null; - - var value = this.data.getUint32(this.position,this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_UINT32; - return value; - } - - /** - * Reads a variable sized unsigned integer (VX -> 16-bit or 32-bit) from the byte stream. - * - * A VX is written as a variable length 2- or 4-byte element. If the index value is less than 65,280 (0xFF00), - * then the index is written as an unsigned two-byte integer. Otherwise the index is written as an unsigned - * four byte integer with bits 24-31 set. When reading an index, if the first byte encountered is 255 (0xFF), - * then the four-byte form is being used and the first byte should be discarded or masked out. - * - * The returned value is in the range 0 to 65279 or 0 to 2147483647. - * @return A VX 16-bit or 32-bit unsigned integer between 0 to 65279 or 0 and 2147483647. - */ - public readVariableSizedUnsignedInt():number{ - - var value:number; - var c = this.readUnsignedByte(); - if(c != 0xFF) - { - value = c << 8; - c = this.readUnsignedByte(); - value |= c; - } - else - { - c = this.readUnsignedByte(); - value = c << 16; - c = this.readUnsignedByte(); - value |= c << 8; - c = this.readUnsignedByte(); - value |= c; - } - return value; - } - - /** - * Fast read for WebGL since only Uint16 numbers are expected - */ - public readU16VX():number{ - return (this.readUnsignedByte() << 8) | this.readUnsignedByte(); - } - /** - * Reads an unsigned 64-bit integer from the byte stream. - * - * The returned value is in the range 0 to 2^64 − 1. - * @return A 64-bit unsigned integer between 0 and 2^64 − 1 - */ - public readUnsignedInt64():UInt64{ - if (!this.validate(ByteArrayBase.SIZE_OF_UINT32)) return null; - - var low = this.data.getUint32(this.position,this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_UINT32; - var high = this.data.getUint32(this.position,this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_UINT32; - return new UInt64(low,high); - } - - /** - * Reads an unsigned 16-bit integer from the byte stream. - * - * The returned value is in the range 0 to 65535. - * @return A 16-bit unsigned integer between 0 and 65535. - */ - public readUnsignedShort():number{ - if (!this.validate(ByteArrayBase.SIZE_OF_UINT16)) return null; - - var value = this.data.getUint16(this.position, this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_UINT16; - return value; - } - - /** - * Reads a UTF-8 string from the byte stream. The string - * is assumed to be prefixed with an unsigned short indicating - * the length in bytes. - * @return UTF-8 encoded string. - */ - public readUTF(): string{ - if (!this.validate(ByteArrayBase.SIZE_OF_UINT16)) return null; - - var length: number = this.data.getUint16(this.position, this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_UINT16; - - if (length > 0) { - return this.readUTFBytes(length); - } else { - return ""; - } - } - - /** - * Reads a sequence of UTF-8 bytes specified by the length - * parameter from the byte stream and returns a string. - * @param length An unsigned short indicating the length of the UTF-8 bytes. - * @return A string composed of the UTF-8 bytes of the specified length. - */ - public readUTFBytes(length: number): string{ - if (!this.validate(length)) return null; - - var _bytes: Uint8Array = new Uint8Array(this.buffer,this.bufferOffset+this.position,length); - this.position += length; - /*var _bytes: Uint8Array = new Uint8Array(new ArrayBuffer(length)); - for (var i = 0; i < length; i++) { - _bytes[i] = this.data.getUint8(this.position++); - }*/ - return this.decodeUTF8(_bytes); - } - public readStandardString(length: number): string{ - if (!this.validate(length)) return null; - - var str:string = ""; - - for (var i = 0; i < length; i++) { - str += String.fromCharCode(this.data.getUint8(this.position++)); - } - return str; - } - public readStringTillNull(keepEvenByte:boolean=true): string{ - - var str:string = ""; - var num:number=0; - while(this.bytesAvailable > 0) { - var _byte:number = this.data.getUint8(this.position++); - num++; - if(_byte != 0){ - str += String.fromCharCode(_byte); - }else{ - if(keepEvenByte && num % 2 != 0){ - this.position++; - } - break; - } - } - return str; - } - - /** - * Writes a Boolean value. A single byte is written according to the value parameter, - * either 1 if true or 0 if false. - * @param value A Boolean value determining which byte is written. If the parameter is true, - * the method writes a 1; if false, the method writes a 0. - */ - public writeBoolean(value: boolean): void{ - this.validateBuffer(ByteArrayBase.SIZE_OF_BOOLEAN); - - this.data.setUint8(this.position++, value ? 1 : 0); - } - - /** - * Writes a byte to the byte stream. - * The low 8 bits of the - * parameter are used. The high 24 bits are ignored. - * @param value A 32-bit integer. The low 8 bits are written to the byte stream. - */ - public writeByte(value: number): void{ - this.validateBuffer(ByteArrayBase.SIZE_OF_INT8); - - this.data.setInt8(this.position++, value); - } - public writeUnsignedByte(value: number):void{ - this.validateBuffer(ByteArrayBase.SIZE_OF_UINT8); - - this.data.setUint8(this.position++, value); - } - /** - * Writes a sequence of length bytes from the - * specified byte array, bytes, - * starting offset(zero-based index) bytes - * into the byte stream. - * - * If the length parameter is omitted, the default - * length of 0 is used; the method writes the entire buffer starting at - * offset. - * If the offset parameter is also omitted, the entire buffer is - * written. If offset or length - * is out of range, they are clamped to the beginning and end - * of the bytes array. - * @param bytes The ByteArrayBase object. - * @param offset A zero-based index indicating the _position into the array to begin writing. - * @param length An unsigned integer indicating how far into the buffer to write. - */ - public writeBytes(_bytes: ByteArrayBase, offset: number= 0, length: number= 0): void{ - this.validateBuffer(length); - - var tmp_data = new DataView(_bytes.buffer); - for(var i=0; i < _bytes.length;i++){ - this.data.setUint8(this.position++,tmp_data.getUint8(i)); - } - } - - /** - * Writes an IEEE 754 double-precision (64-bit) floating-point number to the byte stream. - * @param value A double-precision (64-bit) floating-point number. - */ - public writeDouble(value: number): void{ - this.validateBuffer(ByteArrayBase.SIZE_OF_FLOAT64); - - this.data.setFloat64(this.position, value, this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_FLOAT64; - } - - /** - * Writes an IEEE 754 single-precision (32-bit) floating-point number to the byte stream. - * @param value A single-precision (32-bit) floating-point number. - */ - public writeFloat(value: number): void{ - this.validateBuffer(ByteArrayBase.SIZE_OF_FLOAT32); - - this.data.setFloat32(this.position, value, this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_FLOAT32; - } - - /** - * Writes a 32-bit signed integer to the byte stream. - * @param value An integer to write to the byte stream. - */ - public writeInt(value:number):void{ - this.validateBuffer(ByteArrayBase.SIZE_OF_INT32); - - this.data.setInt32(this.position, value, this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_INT32; - } - - /** - * Writes a multibyte string to the byte stream using the specified character set. - * @param value The string value to be written. - * @param charSet The string denoting the character set to use. Possible character set strings - * include "shift-jis", "cn-gb", "iso-8859-1", and others. - * For a complete list, see Supported Character Sets. - */ - public writeMultiByte(value: string, charSet: string): void{ - - } - - /** - * Writes a 16-bit integer to the byte stream. The low 16 bits of the parameter are used. - * The high 16 bits are ignored. - * @param value 32-bit integer, whose low 16 bits are written to the byte stream. - */ - public writeShort(value: number): void{ - this.validateBuffer(ByteArrayBase.SIZE_OF_INT16); - - this.data.setInt16(this.position, value, this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_INT16; - } - public writeUnsignedShort(value: number): void{ - this.validateBuffer(ByteArrayBase.SIZE_OF_UINT16); - - this.data.setUint16(this.position, value, this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_UINT16; - } - - /** - * Writes a 32-bit unsigned integer to the byte stream. - * @param value An unsigned integer to write to the byte stream. - */ - public writeUnsignedInt(value: number): void{ - this.validateBuffer(ByteArrayBase.SIZE_OF_UINT32); - - this.data.setUint32(this.position, value, this.endian == ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_UINT32; - } - - /** - * Writes a UTF-8 string to the byte stream. The length of the UTF-8 string in bytes - * is written first, as a 16-bit integer, followed by the bytes representing the - * characters of the string. - * @param value The string value to be written. - */ - public writeUTF(value: string): void{ - var utf8bytes: Uint8Array = this.encodeUTF8(value); - var length: number = utf8bytes.length; - - this.validateBuffer(ByteArrayBase.SIZE_OF_UINT16 + length); - - this.data.setUint16(this.position, length, this.endian === ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_UINT16; - this.writeUint8Array(utf8bytes); - } - - /** - * Writes a UTF-8 string to the byte stream. Similar to the writeUTF() method, - * but writeUTFBytes() does not prefix the string with a 16-bit length word. - * @param value The string value to be written. - */ - public writeUTFBytes(value: string): void{ - this.writeUint8Array(this.encodeUTF8(value)); - } - - - public toString():string{ - return "[ByteArrayBase] length:"+this.length+", bytesAvailable:"+this.bytesAvailable; - } - - /****************************/ - /* EXTRA JAVASCRIPT APIs */ - /****************************/ - - /** - * Writes a Uint8Array to the byte stream. - * @param value The Uint8Array to be written. - */ - public writeUint8Array(_bytes: Uint8Array):void { - this.validateBuffer(this.position + _bytes.length); - - for (var i = 0; i < _bytes.length; i++) { - this.data.setUint8(this.position++, _bytes[i]); - } - } - - /** - * Writes a Uint16Array to the byte stream. - * @param value The Uint16Array to be written. - */ - public writeUint16Array(_bytes: Uint16Array): void { - this.validateBuffer(this.position + _bytes.length); - - for (var i = 0; i < _bytes.length; i++) { - this.data.setUint16(this.position, _bytes[i], this.endian === ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_UINT16; - } - } - - /** - * Writes a Uint32Array to the byte stream. - * @param value The Uint32Array to be written. - */ - public writeUint32Array(_bytes: Uint32Array): void { - this.validateBuffer(this.position + _bytes.length); - - for (var i = 0; i < _bytes.length; i++) { - this.data.setUint32(this.position, _bytes[i], this.endian === ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_UINT32; - } - } - - /** - * Writes a Int8Array to the byte stream. - * @param value The Int8Array to be written. - */ - public writeInt8Array(_bytes: Int8Array): void { - this.validateBuffer(this.position + _bytes.length); - - for (var i = 0; i < _bytes.length; i++) { - this.data.setInt8(this.position++, _bytes[i]); - } - } - - /** - * Writes a Int16Array to the byte stream. - * @param value The Int16Array to be written. - */ - public writeInt16Array(_bytes: Int16Array): void { - this.validateBuffer(this.position + _bytes.length); - - for (var i = 0; i < _bytes.length; i++) { - this.data.setInt16(this.position, _bytes[i], this.endian === ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_INT16; - } - } - - /** - * Writes a Int32Array to the byte stream. - * @param value The Int32Array to be written. - */ - public writeInt32Array(_bytes: Int32Array): void { - this.validateBuffer(this.position + _bytes.length); - - for (var i = 0; i < _bytes.length; i++) { - this.data.setInt32(this.position, _bytes[i], this.endian === ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_INT32; - } - } - - /** - * Writes a Float32Array to the byte stream. - * @param value The Float32Array to be written. - */ - public writeFloat32Array(_bytes: Float32Array): void { - this.validateBuffer(this.position + _bytes.length); - - for (var i = 0; i < _bytes.length; i++) { - this.data.setFloat32(this.position, _bytes[i], this.endian === ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_FLOAT32; - } - } - - /** - * Writes a Float64Array to the byte stream. - * @param value The Float64Array to be written. - */ - public writeFloat64Array(_bytes: Float64Array): void { - this.validateBuffer(this.position + _bytes.length); - - for (var i = 0; i < _bytes.length; i++) { - this.data.setFloat64(this.position, _bytes[i], this.endian === ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_FLOAT64; - } - } - - /** - * Read a Uint8Array from the byte stream. - * @param length An unsigned short indicating the length of the Uint8Array. - */ - public readUint8Array(length:number,createNewBuffer:boolean=true):Uint8Array{ - if (!this.validate(length)) return null; - if(!createNewBuffer) { - var result:Uint8Array = new Uint8Array(this.buffer, this.bufferOffset+this.position, length); - this.position += length; - }else { - result = new Uint8Array(new ArrayBuffer(length)); - for (var i = 0; i < length; i++) { - result[i] = this.data.getUint8(this.position); - this.position += ByteArrayBase.SIZE_OF_UINT8; - } - } - return result; - } - - /** - * Read a Uint16Array from the byte stream. - * @param length An unsigned short indicating the length of the Uint16Array. - */ - public readUint16Array(length:number,createNewBuffer:boolean=true):Uint16Array{ - var size:number = length * ByteArrayBase.SIZE_OF_UINT16; - if (!this.validate(size)) return null; - if(!createNewBuffer) { - var result:Uint16Array = new Uint16Array(this.buffer, this.bufferOffset+this.position, length); - this.position += size; - } - else { - result = new Uint16Array(new ArrayBuffer(size)); - for (var i = 0; i < length; i++) { - result[i] = this.data.getUint16(this.position, this.endian === ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_UINT16; - } - } - return result; - } - - /** - * Read a Uint32Array from the byte stream. - * @param length An unsigned short indicating the length of the Uint32Array. - */ - public readUint32Array(length:number,createNewBuffer:boolean=true):Uint32Array{ - var size:number = length * ByteArrayBase.SIZE_OF_UINT32; - if (!this.validate(size)) return null; - if(!createNewBuffer) { - var result:Uint32Array = new Uint32Array(this.buffer, this.bufferOffset+this.position, length); - this.position += size; - } - else { - result = new Uint32Array(new ArrayBuffer(size)); - for (var i = 0; i < length; i++) { - result[i] = this.data.getUint32(this.position, this.endian === ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_UINT32; - } - } - return result; - } - - /** - * Read a Int8Array from the byte stream. - * @param length An unsigned short indicating the length of the Int8Array. - */ - public readInt8Array(length:number,createNewBuffer:boolean=true):Int8Array{ - if (!this.validate(length)) return null; - if(!createNewBuffer) { - var result:Int8Array = new Int8Array(this.buffer, this.bufferOffset+this.position, length); - this.position += length; - } - else { - result = new Int8Array(new ArrayBuffer(length)); - for (var i = 0; i < length; i++) { - result[i] = this.data.getInt8(this.position); - this.position += ByteArrayBase.SIZE_OF_INT8; - } - } - return result; - } - - /** - * Read a Int16Array from the byte stream. - * @param length An unsigned short indicating the length of the Int16Array. - */ - public readInt16Array(length:number,createNewBuffer:boolean=true):Int16Array{ - var size:number = length * ByteArrayBase.SIZE_OF_INT16 - if (!this.validate(size)) return null; - if(!createNewBuffer) { - var result:Int16Array = new Int16Array(this.buffer, this.bufferOffset+this.position, length); - this.position += size; - } - else { - result = new Int16Array(new ArrayBuffer(size)); - for (var i = 0; i < length; i++) { - result[i] = this.data.getInt16(this.position, this.endian === ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_INT16; - } - } - return result; - } - - /** - * Read a Int32Array from the byte stream. - * @param length An unsigned short indicating the length of the Int32Array. - */ - public readInt32Array(length:number,createNewBuffer:boolean=true):Int32Array{ - var size:number = length * ByteArrayBase.SIZE_OF_INT32 - if (!this.validate(size)) return null; - if(!createNewBuffer) { - - if((this.bufferOffset+this.position) % 4 == 0){ - var result:Float32Array = new Int32Array(this.buffer, this.bufferOffset+this.position, length); - this.position += size; - }else{ - var tmp:Uint8Array = new Uint8Array(new ArrayBuffer(size)); - for (var i = 0; i < size; i++) { - tmp[i] = this.data.getUint8(this.position); - this.position += ByteArrayBase.SIZE_OF_UINT8; - } - result = new Int32Array(tmp.buffer); - } - } - else { - result = new Int32Array(new ArrayBuffer(size)); - for (var i = 0; i < length; i++) { - result[i] = this.data.getInt32(this.position, this.endian === ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_INT32; - } - } - return result; - } - - /** - * Read a Float32Array from the byte stream. - * @param length An unsigned short indicating the length of the Float32Array. - */ - public readFloat32Array(length:number,createNewBuffer:boolean=true):Float32Array{ - var size:number = length * ByteArrayBase.SIZE_OF_FLOAT32; - if (!this.validate(size)) return null; - if(!createNewBuffer) { - if((this.bufferOffset+this.position) % 4 == 0){ - var result:Float32Array = new Float32Array(this.buffer, this.bufferOffset+this.position, length); - this.position += size; - }else{ - var tmp:Uint8Array = new Uint8Array(new ArrayBuffer(size)); - for (var i = 0; i < size; i++) { - tmp[i] = this.data.getUint8(this.position); - this.position += ByteArrayBase.SIZE_OF_UINT8; - } - result = new Float32Array(tmp.buffer); - } - } - else { - result = new Float32Array(new ArrayBuffer(size)); - - for (var i = 0; i < length; i++) { - result[i] = this.data.getFloat32(this.position, this.endian === ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_FLOAT32; - } - } - return result; - } - - /** - * Read a Float64Array from the byte stream. - * @param length An unsigned short indicating the length of the Float64Array. - */ - public readFloat64Array(length:number,createNewBuffer:boolean=true):Float64Array{ - var size:number = length * ByteArrayBase.SIZE_OF_FLOAT64 - if (!this.validate(size)) return null; - if(!createNewBuffer) { - var result:Float64Array = new Float64Array(this.buffer, this.position, length); - this.position += size; - }else { - result = new Float64Array(new ArrayBuffer(size)); - for (var i = 0; i < length; i++) { - result[i] = this.data.getFloat64(this.position, this.endian === ByteArrayBase.LITTLE_ENDIAN); - this.position += ByteArrayBase.SIZE_OF_FLOAT64; - } - } - return result; - } - public validate(len:number): boolean { - //len += this.data.byteOffset; - if (this.data.byteLength > 0 && this._position + len <= this.data.byteLength) { - return true; - } else { - throw 'Error #2030: End of file was encountered.'; - } - } - /**********************/ - /* PRIVATE METHODS */ - /**********************/ - private validateBuffer(len: number): void { - this.write_position = len > this.write_position ? len : this.write_position; - if (this.data.byteLength < len) { - var tmp:Uint8Array = new Uint8Array(new ArrayBuffer(len + this.BUFFER_EXT_SIZE)); - tmp.set(new Uint8Array(this.data.buffer)); - this.data.buffer = tmp.buffer; - } - } - - /** - * UTF-8 Encoding/Decoding - */ - private encodeUTF8(str: string): Uint8Array { - var pos: number = 0; - var codePoints = this.stringToCodePoints(str); - var outputBytes = []; - - while (codePoints.length > pos) { - var code_point: number = codePoints[pos++]; - - if (this.inRange(code_point, 0xD800, 0xDFFF)) { - this.encoderError(code_point); - } - else if (this.inRange(code_point, 0x0000, 0x007f)) { - outputBytes.push(code_point); - } else { - var count, offset; - if (this.inRange(code_point, 0x0080, 0x07FF)) { - count = 1; - offset = 0xC0; - } else if (this.inRange(code_point, 0x0800, 0xFFFF)) { - count = 2; - offset = 0xE0; - } else if (this.inRange(code_point, 0x10000, 0x10FFFF)) { - count = 3; - offset = 0xF0; - } - - outputBytes.push(this.div(code_point, Math.pow(64, count)) + offset); - - while (count > 0) { - var temp = this.div(code_point, Math.pow(64, count - 1)); - outputBytes.push(0x80 + (temp % 64)); - count -= 1; - } - } - } - return new Uint8Array(outputBytes); - } - private decodeUTF8(data: Uint8Array): string { - var fatal: boolean = false; - var pos: number = 0; - var result: string = ""; - var code_point: number; - var utf8_code_point = 0; - var utf8_bytes_needed = 0; - var utf8_bytes_seen = 0; - var utf8_lower_boundary = 0; - - while (data.length > pos) { - - var _byte = data[pos++]; - - if (_byte === this.EOF_byte) { - if (utf8_bytes_needed !== 0) { - code_point = this.decoderError(fatal); - } else { - code_point = this.EOF_code_point; - } - } else { - - if (utf8_bytes_needed === 0) { - if (this.inRange(_byte, 0x00, 0x7F)) { - code_point = _byte; - } else { - if (this.inRange(_byte, 0xC2, 0xDF)) { - utf8_bytes_needed = 1; - utf8_lower_boundary = 0x80; - utf8_code_point = _byte - 0xC0; - } else if (this.inRange(_byte, 0xE0, 0xEF)) { - utf8_bytes_needed = 2; - utf8_lower_boundary = 0x800; - utf8_code_point = _byte - 0xE0; - } else if (this.inRange(_byte, 0xF0, 0xF4)) { - utf8_bytes_needed = 3; - utf8_lower_boundary = 0x10000; - utf8_code_point = _byte - 0xF0; - } else { - this.decoderError(fatal); - } - utf8_code_point = utf8_code_point * Math.pow(64, utf8_bytes_needed); - code_point = null; - } - } else if (!this.inRange(_byte, 0x80, 0xBF)) { - utf8_code_point = 0; - utf8_bytes_needed = 0; - utf8_bytes_seen = 0; - utf8_lower_boundary = 0; - pos--; - code_point = this.decoderError(fatal,_byte); - } else { - - utf8_bytes_seen += 1; - utf8_code_point = utf8_code_point + (_byte - 0x80) * Math.pow(64, utf8_bytes_needed - utf8_bytes_seen); - - if (utf8_bytes_seen !== utf8_bytes_needed) { - code_point = null; - } else { - - var cp = utf8_code_point; - var lower_boundary = utf8_lower_boundary; - utf8_code_point = 0; - utf8_bytes_needed = 0; - utf8_bytes_seen = 0; - utf8_lower_boundary = 0; - if (this.inRange(cp, lower_boundary, 0x10FFFF) && !this.inRange(cp, 0xD800, 0xDFFF)) { - code_point = cp; - } else { - code_point = this.decoderError(fatal,_byte); - } - } - - } - } - //Decode string - if (code_point !== null && code_point !== this.EOF_code_point) { - if (code_point <= 0xFFFF) { - if(code_point > 0)result += String.fromCharCode(code_point); - } else { - code_point -= 0x10000; - result += String.fromCharCode(0xD800 + ((code_point >> 10) & 0x3ff)); - result += String.fromCharCode(0xDC00 + (code_point & 0x3ff)); - } - } - } - return result; - } - private encoderError(code_point) { - throw 'EncodingError! The code point ' + code_point + ' could not be encoded.'; - } - private decoderError(fatal, opt_code_point?): number { - if(fatal){ - throw 'DecodingError'; - } - return opt_code_point || 0xFFFD; - } - private EOF_byte: number = -1; - private EOF_code_point: number = -1; - - private inRange(a, min, max) { - return min <= a && a <= max; - } - private div(n, d) { - return Math.floor(n / d); - } - private stringToCodePoints(string) { - /** @type {Array.} */ - var cps = []; - // Based on http://www.w3.org/TR/WebIDL/#idl-DOMString - var i = 0, n = string.length; - while (i < string.length) { - var c = string.charCodeAt(i); - if (!this.inRange(c, 0xD800, 0xDFFF)) { - cps.push(c); - } else if (this.inRange(c, 0xDC00, 0xDFFF)) { - cps.push(0xFFFD); - } else { // (inRange(c, 0xD800, 0xDBFF)) - if (i === n - 1) { - cps.push(0xFFFD); - } else { - var d = string.charCodeAt(i + 1); - if (this.inRange(d, 0xDC00, 0xDFFF)) { - var a = c & 0x3FF; - var b = d & 0x3FF; - i += 1; - cps.push(0x10000 + (a << 10) + b); - } else { - cps.push(0xFFFD); - } - } - } - i += 1; - } - return cps; - } - } -} diff --git a/src/CompressionAlgorithm.ts b/src/CompressionAlgorithm.ts deleted file mode 100644 index 845b831..0000000 --- a/src/CompressionAlgorithm.ts +++ /dev/null @@ -1,15 +0,0 @@ -module nid.utils -{ - /** - * JavaScript ByteArray - * version : 0.2 - * @author Nidin Vinayakan | nidinthb@gmail.com - */ - export class CompressionAlgorithm{ - - static DEFLATE:string = "deflate"; - static LZMA:string = "lzma"; - static ZLIB:string = "zlib"; - - } -} \ No newline at end of file diff --git a/src/HalfPrecisionWriter.ts b/src/HalfPrecisionWriter.ts deleted file mode 100644 index 079077a..0000000 --- a/src/HalfPrecisionWriter.ts +++ /dev/null @@ -1,126 +0,0 @@ -/****************************************************************************** - * This file contains code licensed for use under the BSD license, and was - * modified from the original C source by James Tursa as provided at the - * MatLab Central site here: - * - * http://www.mathworks.com/matlabcentral/fileexchange/23173 - * - * It has been modified to compile under ActionScript 3 for handling the - * FLOAT16 data format used in Adobe's SWF file format, which is the same - * as the IEEE 754r Half Precision format implemented by Mr. Tursa in the - * original source. - * - * The original license follows: - * - * Copyright (c) 2009, James Tursa - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the distribution - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/// -module nid.utils -{ - - export class HalfPrecisionWriter - { - - static write(value:number, data:BitArray) - { - - data.resetBitsPending(); - - var dword:number; - var sign:number; - var exponent:number; - var significand:number; - var halfSignificand:number; - var signedExponent:number; - var result:number; - var p:number; - - p = data.position; - data.writeDouble(value); - data.position -= 4; - dword = data.readUnsignedInt(); - data.position = p; - - if ((dword & 0x7FFFFFFF) == 0) { // Signed zero - result = dword >> 16; - } - else { - - sign = dword & 0x80000000; - exponent = dword & 0x7FF00000; - significand = dword & 0x000FFFFF; - - if (exponent == 0) { // Denormal will underflow, signed zero - result = sign >> 16; - } - else if (exponent == 0x7FF00000) { // Infinity or NaN (all exponent bits set) - if (significand == 0) { - result = ((sign >> 16) | 0x7C00); // Signed infinity - } - else { - result = 0xFE00; // NaN, only 1st mantissa bit is set - } - } - else { // Normalized number - sign = sign >> 16; - signedExponent = (exponent >> 20) - 1023 + 15; // Reset the bias to half-precision - if (signedExponent >= 0x1F) { // Overflow - result = ((significand >> 16) | 0x7C00); // Signed infinity - } - else if (signedExponent <= 0) { // Underflow - if ((10 - signedExponent) > 21) { // Significand shifted off and no rounding possible - halfSignificand = 0; - } - else { - significand |= 0x00100000; // Add leading bit - halfSignificand = (significand >> (11 - signedExponent)); - if ((significand >> (10 - signedExponent)) & 0x00000001) { // Check for rounding - halfSignificand += 1; // Round, might overflow into exponent (okay) - } - } - result = (sign | halfSignificand); - } - else { - exponent = signedExponent << 10; - halfSignificand = significand >> 10; - if (significand & 0x00000200) { // Check for rounding - result = (sign | exponent | halfSignificand) + 1; // Round, may overflow to infinity (okay) - } - else { - result = (sign | exponent | halfSignificand); - } - } - } - } - - data.writeShort(result); - data.length = p + 2; - - } - - } -} diff --git a/src/IByteArray.ts b/src/IByteArray.ts deleted file mode 100644 index de4bd42..0000000 --- a/src/IByteArray.ts +++ /dev/null @@ -1,16 +0,0 @@ -/** - * JavaScript ByteArray - * version : 0.2 - * @author Nidin Vinayakan | nidinthb@gmail.com - * - * ActionScript3 ByteArray implementation in JavaScript - * limitation : size of ByteArray cannot be changed - * - */ -module nid.utils -{ - - export interface IByteArray{ - - } -} \ No newline at end of file diff --git a/src/LZMAHelper.ts b/src/LZMAHelper.ts deleted file mode 100644 index d2271af..0000000 --- a/src/LZMAHelper.ts +++ /dev/null @@ -1,72 +0,0 @@ -/// -module nid.utils{ - - export class LZMAHelper{ - static decoder:LZMA = new LZMA(); - static decoderAsync:Worker; - static enableAsync:boolean = false; - static callback:Function; - static ENCODE:number = 1; - static DECODE:number = 2; - - static init():void{ - var command = 0; - if(LZMAHelper.enableAsync){ - LZMAHelper.decoderAsync = new Worker('LZMAWorker.min.js'); - LZMAHelper.decoderAsync.onmessage = function(e){ - if(command == 0){ - command = e.data; - }else if(command == LZMAHelper.ENCODE){ - command = 0;//encode not implemented - }else if(command == LZMAHelper.DECODE){ - command = 0; - LZMAHelper.callback(e.data); - LZMAHelper.callback = null; - } - } - } - } - - /** - * TODO : Implement encoder - * @param data - * @returns {null} - */ - static encode(data:ArrayBuffer):ArrayBuffer{ - return null; - } - static decodeBuffer(data:ArrayBuffer):ArrayBuffer{ - return LZMAHelper.decoder.decode(new Uint8Array(data)).buffer; - } - static decode(data:Uint8Array):Uint8Array{ - return LZMAHelper.decoder.decode(data); - } - - /** - * TODO : Implement encoder - * @param data - * @param _callback - */ - static encodeAsync(data:ArrayBuffer,_callback:Function):void{ - if(LZMAHelper.enableAsync) { - - }else{ - console.log('Error! Asynchronous encoding is disabled'); - } - } - static decodeAsync(data:ArrayBuffer,_callback:Function):void{ - if(LZMAHelper.enableAsync) { - if (LZMAHelper.callback == null) { - LZMAHelper.callback = _callback; - LZMAHelper.decoderAsync.postMessage(LZMAHelper.DECODE); - LZMAHelper.decoderAsync.postMessage(data, [data]); - } else { - console.log('Warning! Another LZMA decoding is running...'); - } - }else{ - console.log('Error! Asynchronous decoding is disabled'); - } - } - } -} -nid.utils.LZMAHelper.init(); \ No newline at end of file diff --git a/src/MEMORY.ts b/src/MEMORY.ts deleted file mode 100644 index a143ea3..0000000 --- a/src/MEMORY.ts +++ /dev/null @@ -1,40 +0,0 @@ -module nid.utils -{ - export class MEMORY - { - static u8Index:number=0; - static u16Index:number=0; - static u32Index:number=0; - static u8:Uint32Array; - static u16:Uint32Array; - static u32:Uint32Array; - - static allocateUint8(len:number):void{ - MEMORY.u8 = new Uint8Array(len); - } - static allocateUint16(len:number):void{ - MEMORY.u16 = new Uint16Array(len); - } - static allocateUint32(len:number):void{ - MEMORY.u32 = new Uint32Array(len); - } - static getUint8():number{ - if(!MEMORY.u8){ - MEMORY.allocateUint8(10); - } - return MEMORY.u8Index++; - } - static getUint16():number{ - if(!MEMORY.u16){ - MEMORY.allocateUint16(24); - } - return MEMORY.u16Index++; - } - static getUint32():number{ - if(!MEMORY.u32){ - MEMORY.allocateUint32(10); - } - return MEMORY.u32Index++; - } - } -} \ No newline at end of file diff --git a/src/ZLIBHelper.ts b/src/ZLIBHelper.ts deleted file mode 100644 index 06005c4..0000000 --- a/src/ZLIBHelper.ts +++ /dev/null @@ -1,65 +0,0 @@ -/// -module nid.utils{ - - export class ZLIBHelper{ - static decoder:ZLIB = new ZLIB(); - static decoderAsync:Worker = new Worker('ZLIBWorker.min.js'); - static callback:Function; - static ENCODE:number = 1; - static DECODE:number = 2; - - static init():void{ - var command = 0; - ZLIBHelper.decoderAsync.onmessage = function(e){ - if(command == 0){ - command = e.data; - }else if(command == ZLIBHelper.ENCODE){ - command = 0;//encode not implemented - }else if(command == ZLIBHelper.DECODE){ - command = 0; - ZLIBHelper.callback(e.data); - ZLIBHelper.callback = null; - } - } - } - - /** - * TODO : Implement encoder - * @param data - * @returns {null} - */ - static encodeBuffer(data:ArrayBuffer):ArrayBuffer{ - throw "ZLIB encoder not implemented!"; - return null; - } - static encode(data:Uint8Array):Uint8Array{ - throw "ZLIB encoder not implemented!"; - return null; - } - static decodeBuffer(data:ArrayBuffer):ArrayBuffer{ - return ZLIBHelper.decoder.decode(new Uint8Array(data)).buffer; - } - static decode(data:Uint8Array):Uint8Array{ - return ZLIBHelper.decoder.decode(data); - } - - /** - * TODO : Implement encoder - * @param data - * @param _callback - */ - static encodeBufferAsync(data:ArrayBuffer,_callback:Function):void{ - - } - static decodeBufferAsync(data:ArrayBuffer,_callback:Function):void{ - if(ZLIBHelper.callback == null){ - ZLIBHelper.callback = _callback; - ZLIBHelper.decoderAsync.postMessage(ZLIBHelper.DECODE); - ZLIBHelper.decoderAsync.postMessage(data,[data]); - }else{ - console.log('Warning! Another ZLIB decoding is running...'); - } - } - } -} -nid.utils.ZLIBHelper.init(); \ No newline at end of file diff --git a/src/ctypes/Int64.ts b/src/ctypes/Int64.ts index 4cd9f3b..07cfd97 100644 --- a/src/ctypes/Int64.ts +++ b/src/ctypes/Int64.ts @@ -4,38 +4,34 @@ * @author Nidin Vinayakan | nidinthb@gmail.com * */ -module ctypes -{ - export class Int64 - { - public low:number; - public high:number; - public _value:number; +export class Int64 { + public low:number; + public high:number; + public _value:number; - constructor(low:number,high:number){ - this.low = low; - this.high = high; - } - public value():number - { - //this._value = (this.low | (this.high << 32)); - var _h:string = this.high.toString(16); - var _hd:number = 8 - _h.length; - if(_hd > 0){ - for(var i=0;i<_hd;i++){ - _h = '0'+_h; - } + constructor(low:number, high:number) { + this.low = low; + this.high = high; + } + + public value():number { + //this._value = (this.low | (this.high << 32)); + var _h:string = this.high.toString(16); + var _hd:number = 8 - _h.length; + if (_hd > 0) { + for (var i = 0; i < _hd; i++) { + _h = '0' + _h; } - var _l:string = this.low.toString(16); - var _ld:number = 8 - _l.length; - if(_ld > 0){ - for(i=0;i<_ld;i++){ - _l = '0'+_l; - } + } + var _l:string = this.low.toString(16); + var _ld:number = 8 - _l.length; + if (_ld > 0) { + for (i = 0; i < _ld; i++) { + _l = '0' + _l; } - this._value = Number('0x' + _h + _l); - return this._value; } - + this._value = Number('0x' + _h + _l); + return this._value; } + } \ No newline at end of file diff --git a/src/ctypes/UInt64.ts b/src/ctypes/UInt64.ts index 77642c8..2745089 100644 --- a/src/ctypes/UInt64.ts +++ b/src/ctypes/UInt64.ts @@ -4,38 +4,34 @@ * @author Nidin Vinayakan | nidinthb@gmail.com * */ -module ctypes -{ - export class UInt64 - { - public low:number; - public high:number; - public _value:number; +export class UInt64 { + public low:number; + public high:number; + public _value:number; - constructor(low:number=0,high:number=0){ - this.low = low; - this.high = high; - } - public value():number - { - //this._value = (this.low | (this.high << 32)); - var _h:string = this.high.toString(16); - var _hd:number = 8 - _h.length; - if(_hd > 0){ - for(var i=0;i<_hd;i++){ - _h = '0'+_h; - } + constructor(low:number = 0, high:number = 0) { + this.low = low; + this.high = high; + } + + public value():number { + //this._value = (this.low | (this.high << 32)); + var _h:string = this.high.toString(16); + var _hd:number = 8 - _h.length; + if (_hd > 0) { + for (var i = 0; i < _hd; i++) { + _h = '0' + _h; } - var _l:string = this.low.toString(16); - var _ld:number = 8 - _l.length; - if(_ld > 0){ - for(i=0;i<_ld;i++){ - _l = '0'+_l; - } + } + var _l:string = this.low.toString(16); + var _ld:number = 8 - _l.length; + if (_ld > 0) { + for (i = 0; i < _ld; i++) { + _l = '0' + _l; } - this._value = Number('0x' + _h + _l); - return this._value; } - + this._value = Number('0x' + _h + _l); + return this._value; } + } \ No newline at end of file diff --git a/src/ctypes/ctypes.d.ts b/src/ctypes/ctypes.d.ts deleted file mode 100644 index f6ada62..0000000 --- a/src/ctypes/ctypes.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -/// -/// \ No newline at end of file diff --git a/src/lzma/BitTreeDecoder.ts b/src/lzma/BitTreeDecoder.ts deleted file mode 100644 index 905049e..0000000 --- a/src/lzma/BitTreeDecoder.ts +++ /dev/null @@ -1,42 +0,0 @@ -/// -module nid.utils -{ - /** - * LZMA Decoder - * @author Nidin Vinayakan | nidinthb@gmail.com - */ - export class BitTreeDecoder - { - public probs:Uint16Array; - private numBits:number; - - - constructor(numBits){ - this.numBits = numBits; - this.probs = new Uint16Array(1 << this.numBits); - - } - public init():void{ - LZMA.INIT_PROBS(this.probs); - } - public decode(rc:RangeDecoder):number - { - var m:number = 1;//Uint16 - for (var i:number = 0; i < this.numBits; i++) - m = (m << 1) + rc.decodeBit(this.probs,m); - return m - (1 << this.numBits); - } - public reverseDecode(rc:RangeDecoder):number - { - return LZMA.BitTreeReverseDecode(this.probs, this.numBits, rc); - } - static constructArray(numBits:number,len:number):Array - { - var vec:BitTreeDecoder[] = []; - for(var i:number = 0; i < len; i++){ - vec[i] = new BitTreeDecoder(numBits); - } - return vec; - } - } -} diff --git a/src/lzma/LZMA.lib.d.ts b/src/lzma/LZMA.lib.d.ts deleted file mode 100644 index 815177f..0000000 --- a/src/lzma/LZMA.lib.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -/// -/// -/// -/// -/// -/// -/// diff --git a/src/lzma/LZMA.ts b/src/lzma/LZMA.ts deleted file mode 100644 index a2599a0..0000000 --- a/src/lzma/LZMA.ts +++ /dev/null @@ -1,134 +0,0 @@ -/// -module nid.utils -{ - "use strict" - /** - * LZMA Decoder - * @author Nidin Vinayakan | nidinthb@gmail.com - * - */ - - export class LZMA - { - static LZMA_DIC_MIN:number = (1 << 12); - static LZMA_RES_ERROR:number = 0; - static LZMA_RES_FINISHED_WITH_MARKER:number = 1; - static LZMA_RES_FINISHED_WITHOUT_MARKER:number = 2; - static kNumBitModelTotalBits:number = 11; - static kNumMoveBits:number = 5; - static PROB_INIT_VAL = ((1 << LZMA.kNumBitModelTotalBits) / 2);//1024 - static kNumPosBitsMax:number = 4; - - static kNumStates:number = 12; - static kNumLenToPosStates:number = 4; - static kNumAlignBits:number = 4; - static kStartPosModelIndex:number = 4; - static kEndPosModelIndex:number = 14; - static kNumFullDistances:number = (1 << (LZMA.kEndPosModelIndex >>> 1)); - static kMatchMinLen:number = 2; - - public decoder:LzmaDecoder; - public data:Uint8Array; - public ucdata:Uint8Array; - - //Local registers - private loc1:number; - private loc2:number; - - static INIT_PROBS(p:Uint16Array):void{ - for (var i:number = 0; i < p.length; i++) { - p[i] = this.PROB_INIT_VAL; - } - } - static BitTreeReverseDecode(probs,numBits:number, rc:RangeDecoder,offset:number=0):number - { - var m:number = 1; - var symbol:number = 0; - for (var i:number = 0; i < numBits; i++) - { - var bit:number = rc.decodeBit(probs,offset+m); - m <<= 1; - m += bit; - symbol |= (bit << i); - } - return symbol; - } - constructor(){ - this.decoder = new LzmaDecoder(); - } - public decode(data:Uint8Array):Uint8Array - { - this.data = data; - //var header:Uint8Array = data.readUint8Array(13); - var header:Uint8Array = new Uint8Array(13); - var i:number;//int - for (i = 0; i < 13; i++){ - header[i] = data[i]; - } - - this.decoder.decodeProperties(header); - - console.log("\nlc="+this.decoder.lc+", lp="+this.decoder.lp+", pb="+this.decoder.pb); - console.log("\nDictionary Size in properties = "+this.decoder.dictSizeInProperties); - console.log("\nDictionary Size for decoding = "+this.decoder.dictSize); - //return this.ucdata; - var unpackSize:number = 0;//UInt64 - var unpackSizeDefined:boolean = false; - for (i = 0; i < 8; i++) - { - var b:number = header[5 + i]; - if (b != 0xFF){ - unpackSizeDefined = true; - } - unpackSize |= b << (8 * i); - } - - this.decoder.markerIsMandatory = !unpackSizeDefined; - - console.log("\n"); - if (unpackSizeDefined){ - console.log("Uncompressed Size : "+ unpackSize +" bytes"); - }else{ - console.log("End marker is expected\n"); - } - this.decoder.rangeDec.inStream = data; - console.log("\n"); - - this.decoder.create(); - // we support the streams that have uncompressed size and marker. - var res:number = this.decoder.decode(unpackSizeDefined, unpackSize); //int - - console.log("Read ", this.decoder.rangeDec.in_pos); - console.log("Written ", this.decoder.outWindow.out_pos); - - if (res == LZMA.LZMA_RES_ERROR){ - throw "LZMA decoding error"; - } - else if (res == LZMA.LZMA_RES_FINISHED_WITHOUT_MARKER){ - console.log("Finished without end marker"); - } - else if (res == LZMA.LZMA_RES_FINISHED_WITH_MARKER) - { - if (unpackSizeDefined) - { - if (this.decoder.outWindow.out_pos != unpackSize){ - throw "Finished with end marker before than specified size"; - } - console.log("Warning: "); - } - console.log("Finished with end marker"); - } - else{ - throw "Internal Error"; - } - - console.log("\n"); - - if (this.decoder.rangeDec.corrupted) - { - console.log("\nWarning: LZMA stream is corrupted\n"); - } - return this.decoder.outWindow.outStream; - } - } -} \ No newline at end of file diff --git a/src/lzma/LZMAWorker.ts b/src/lzma/LZMAWorker.ts deleted file mode 100644 index 21adfa3..0000000 --- a/src/lzma/LZMAWorker.ts +++ /dev/null @@ -1,34 +0,0 @@ -/// -module nid.utils{ - - "use strict" - export class LZMAWorker - { - static ENCODE:number = 1; - static DECODE:number = 2; - private decoder:LZMA; - private command:number = 0; - - constructor () - { - var _this = this; - this.decoder = new LZMA(); - - addEventListener('message', (e:any) => { - if(_this.command == 0){ - _this.command = e.data; - }else if(_this.command == 1){ - _this.command = 0; - }else if(_this.command == 2){ - _this.decode(e.data); - } - }, false); - } - private decode(data):void{ - var result = this.decoder.decode(new Uint8Array(data)); - ( postMessage)(LZMAWorker.DECODE); - ( postMessage)(result.buffer,[result.buffer]); - } - } -} -var zlma_w = new nid.utils.LZMAWorker(); \ No newline at end of file diff --git a/src/lzma/LenDecoder.ts b/src/lzma/LenDecoder.ts deleted file mode 100644 index 9cbd3b3..0000000 --- a/src/lzma/LenDecoder.ts +++ /dev/null @@ -1,41 +0,0 @@ -/// -module nid.utils { - /** - * LZMA Decoder - * @author Nidin Vinayakan | nidinthb@gmail.com - */ - - export class LenDecoder { - - private choice; - private lowCoder:Array;//3 - private midCoder:Array;//3 - private highCoder:BitTreeDecoder;//8 - - constructor() { - this.lowCoder = BitTreeDecoder.constructArray(3, 1 << LZMA.kNumPosBitsMax ); - this.midCoder = BitTreeDecoder.constructArray(3, 1 << LZMA.kNumPosBitsMax ); - this.highCoder = new BitTreeDecoder(8); - } - - public init():void { - this.choice = [LZMA.PROB_INIT_VAL,LZMA.PROB_INIT_VAL]; - this.highCoder.init(); - for (var i:number = 0; i < (1 << LZMA.kNumPosBitsMax); i++) - { - this.lowCoder[i].init(); - this.midCoder[i].init(); - } - } - public decode(rc:RangeDecoder, posState:number):number - { - if (rc.decodeBit(this.choice,0) == 0){ - return this.lowCoder[posState].decode(rc); - } - if (rc.decodeBit(this.choice,1) == 0){ - return 8 + this.midCoder[posState].decode(rc); - } - return 16 + this.highCoder.decode(rc); - } - } -} \ No newline at end of file diff --git a/src/lzma/LzmaDecoder.ts b/src/lzma/LzmaDecoder.ts deleted file mode 100644 index 15aa53c..0000000 --- a/src/lzma/LzmaDecoder.ts +++ /dev/null @@ -1,319 +0,0 @@ -/// -module nid.utils -{ - /** - * LZMA Decoder - * @author Nidin Vinayakan | nidinthb@gmail.com - */ - import MEMORY = nid.utils.MEMORY; - - export class LzmaDecoder - { - //Public - public markerIsMandatory:boolean; - public rangeDec:RangeDecoder;//RangeDecoder - public outWindow:OutWindow;//OutWindow - public lc:number; - public pb:number; - public lp:number;//unsigned byte - public dictSize:number;//UInt32 - public dictSizeInProperties:number;//UInt32 - - //Private - private litProbs:Uint16Array; - - private posSlotDecoder:Array; - private alignDecoder:BitTreeDecoder; - private posDecoders:Uint16Array; - - private isMatch:Uint16Array; - private isRep:Uint16Array; - private isRepG0:Uint16Array; - private isRepG1:Uint16Array; - private isRepG2:Uint16Array; - private isRep0Long:Uint16Array; - - private lenDecoder:LenDecoder; - private repLenDecoder:LenDecoder; - - //Local registers - private loc1:number; - private loc2:number; - private matchBitI:number; - private matchByteI:number; - private bitI:number; - private symbolI:number; - private prevByteI:number; - private litStateI:number; - - constructor() { - this.posSlotDecoder = BitTreeDecoder.constructArray(6,LZMA.kNumLenToPosStates);//6 - this.alignDecoder = new BitTreeDecoder(LZMA.kNumAlignBits); - this.posDecoders = new Uint16Array(1 + LZMA.kNumFullDistances - LZMA.kEndPosModelIndex); - - this.isMatch = new Uint16Array(LZMA.kNumStates << LZMA.kNumPosBitsMax); - this.isRep = new Uint16Array(LZMA.kNumStates); - this.isRepG0 = new Uint16Array(LZMA.kNumStates); - this.isRepG1 = new Uint16Array(LZMA.kNumStates); - this.isRepG2 = new Uint16Array(LZMA.kNumStates); - this.isRep0Long = new Uint16Array(LZMA.kNumStates << LZMA.kNumPosBitsMax); - - this.lenDecoder = new LenDecoder(); - this.repLenDecoder = new LenDecoder(); - this.rangeDec = new RangeDecoder(); - this.outWindow = new OutWindow(); - } - - public init():void - { - this.loc1 = MEMORY.getUint32() | 0; - this.loc2 = MEMORY.getUint32() | 0; - this.matchBitI = MEMORY.getUint16() | 0; - this.matchByteI = MEMORY.getUint16() | 0; - this.bitI = MEMORY.getUint16() | 0; - this.symbolI = MEMORY.getUint16() | 0; - this.prevByteI = MEMORY.getUint16() | 0; - this.litStateI = MEMORY.getUint16() | 0; - - this.initLiterals(); - this.initDist(); - - LZMA.INIT_PROBS(this.isMatch); - LZMA.INIT_PROBS(this.isRep); - LZMA.INIT_PROBS(this.isRepG0); - LZMA.INIT_PROBS(this.isRepG1); - LZMA.INIT_PROBS(this.isRepG2); - LZMA.INIT_PROBS(this.isRep0Long); - - this.lenDecoder.init(); - this.repLenDecoder.init(); - } - public create():void - { - this.outWindow.create(this.dictSize); - this.createLiterals(); - } - //Private - private createLiterals():void - { - this.litProbs = new Uint16Array(0x300 << (this.lc + this.lp)); - } - private initLiterals():void - { - var num:number = 0x300 << (this.lc + this.lp);//UInt32 - for (var i:number = 0; i < num; i++) { - this.litProbs[i] = LZMA.PROB_INIT_VAL; - } - } - private decodeLiteral(state, rep0):void//unsigned , UInt32 - { - MEMORY.u16[this.prevByteI] = 0;//unsigned byte - if (!this.outWindow.isEmpty()) - MEMORY.u16[this.prevByteI] = this.outWindow.getByte(1); - - MEMORY.u16[this.symbolI] = 1; - MEMORY.u16[this.litStateI] = ((this.outWindow.totalPos & ((1 << this.lp) - 1)) << this.lc) + (MEMORY.u16[this.prevByteI] >>> (8 - this.lc)); - var probsOffset:number = (0x300 * MEMORY.u16[this.litStateI]) | 0; - - if (state >= 7) - { - MEMORY.u16[this.matchByteI] = this.outWindow.getByte(rep0 + 1); - do - { - MEMORY.u16[this.matchBitI] = (MEMORY.u16[this.matchByteI] >>> 7) & 1; - MEMORY.u16[this.matchByteI] <<= 1; - MEMORY.u16[this.bitI] = this.rangeDec.decodeBit(this.litProbs,probsOffset + ((1 + MEMORY.u16[this.matchBitI]) << 8) + MEMORY.u16[this.symbolI]); - MEMORY.u16[this.symbolI] = (MEMORY.u16[this.symbolI] << 1) | MEMORY.u16[this.bitI]; - if (MEMORY.u16[this.matchBitI] != MEMORY.u16[this.bitI]) - break; - } - while (MEMORY.u16[this.symbolI] < 0x100); - } - while (MEMORY.u16[this.symbolI] < 0x100){ - MEMORY.u16[this.symbolI] = (MEMORY.u16[this.symbolI] << 1) | this.rangeDec.decodeBit(this.litProbs,probsOffset + MEMORY.u16[this.symbolI]); - } - this.outWindow.putByte(MEMORY.u16[this.symbolI] - 0x100); - } - - private decodeDistance(len):number//unsigned byte - { - var lenState:number = len;//unsigned byte - if (lenState > LZMA.kNumLenToPosStates - 1) - lenState = LZMA.kNumLenToPosStates - 1; - - var posSlot = this.posSlotDecoder[lenState].decode(this.rangeDec);//unsigned byte - if (posSlot < 4) - return posSlot; - - var numDirectBits = ((posSlot >>> 1) - 1);//unsigned byte - MEMORY.u32[this.loc1] = ((2 | (posSlot & 1)) << numDirectBits);//UInt32 - if (posSlot < LZMA.kEndPosModelIndex){ - MEMORY.u32[this.loc1] += LZMA.BitTreeReverseDecode(this.posDecoders, numDirectBits, this.rangeDec, MEMORY.u32[this.loc1] - posSlot); - } - else - { - MEMORY.u32[this.loc1] += this.rangeDec.decodeDirectBits(numDirectBits - LZMA.kNumAlignBits) << LZMA.kNumAlignBits; - MEMORY.u32[this.loc1] += this.alignDecoder.reverseDecode(this.rangeDec); - } - return MEMORY.u32[this.loc1]; - } - private initDist():void - { - for (var i = 0; i < LZMA.kNumLenToPosStates; i++){ - this.posSlotDecoder[i].init(); - } - this.alignDecoder.init(); - LZMA.INIT_PROBS(this.posDecoders); - } - public decodeProperties(properties:Uint8Array):void - { - var prop = new Uint8Array(4); - prop[0] = properties[0]; - if (prop[0] >= (9 * 5 * 5)){ - throw "Incorrect LZMA properties"; - } - prop[1] = prop[0] % 9; - prop[0] /= 9; - prop[2] = prop[0] / 5; - prop[3] = prop[0] % 5; - - this.lc = prop[1]; - this.pb = prop[2]; - this.lp = prop[3]; - - this.dictSizeInProperties = 0; - for (var i:number = 0; i < 4; i++){ - this.dictSizeInProperties |= properties[i + 1] << (8 * i); - } - - this.dictSize = this.dictSizeInProperties; - - if (this.dictSize < LZMA.LZMA_DIC_MIN){ - this.dictSize = LZMA.LZMA_DIC_MIN; - } - } - private updateState_Literal(state:number):number - { - if (state < 4) return 0; - else if (state < 10) return state - 3; - else return state - 6; - } - private updateState_ShortRep(state:number):number { return state < 7 ? 9 : 11; } - private updateState_Rep (state:number):number { return state < 7 ? 8 : 11; } - private updateState_Match (state:number):number { return state < 7 ? 7 : 10; } - - public decode(unpackSizeDefined:boolean, unpackSize:number):number//UInt64 - { - this.init(); - this.rangeDec.init(); - - if(unpackSizeDefined){ - this.outWindow.outStream = new Uint8Array(new ArrayBuffer(unpackSize)); - } - - var rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0;//UInt32 - var state = 0;//unsigned byte - - for (;;) - { - if (unpackSizeDefined && unpackSize == 0 && !this.markerIsMandatory){ - if (this.rangeDec.isFinishedOK()){ - return LZMA.LZMA_RES_FINISHED_WITHOUT_MARKER; - } - } - - var posState = this.outWindow.totalPos & ((1 << this.pb) - 1); - - if (this.rangeDec.decodeBit(this.isMatch,(state << LZMA.kNumPosBitsMax) + posState) == 0) - { - if (unpackSizeDefined && unpackSize == 0){ - return LZMA.LZMA_RES_ERROR; - } - this.decodeLiteral(state, rep0); - state = this.updateState_Literal(state); - unpackSize--; - continue; - } - - var len; - - if (this.rangeDec.decodeBit(this.isRep,state) != 0) - { - if (unpackSizeDefined && unpackSize == 0){ - return LZMA.LZMA_RES_ERROR; - } - if (this.outWindow.isEmpty()){ - return LZMA.LZMA_RES_ERROR; - } - if (this.rangeDec.decodeBit(this.isRepG0,state) == 0) - { - if (this.rangeDec.decodeBit(this.isRep0Long,(state << LZMA.kNumPosBitsMax) + posState) == 0) - { - state = this.updateState_ShortRep(state); - this.outWindow.putByte(this.outWindow.getByte(rep0 + 1)); - unpackSize--; - continue; - } - } - else - { - var dist:number; - if (this.rangeDec.decodeBit(this.isRepG1,state) == 0){ - dist = rep1; - } - else - { - if (this.rangeDec.decodeBit(this.isRepG2,state) == 0){ - dist = rep2; - } - else - { - dist = rep3; - rep3 = rep2; - } - rep2 = rep1; - } - rep1 = rep0; - rep0 = dist; - } - len = this.repLenDecoder.decode(this.rangeDec, posState); - state = this.updateState_Rep(state); - } - else - { - rep3 = rep2; - rep2 = rep1; - rep1 = rep0; - len = this.lenDecoder.decode(this.rangeDec, posState); - state = this.updateState_Match(state); - rep0 = this.decodeDistance(len); - if (rep0 == 0xFFFFFFFF) { - return this.rangeDec.isFinishedOK() ? - LZMA.LZMA_RES_FINISHED_WITH_MARKER : - LZMA.LZMA_RES_ERROR; - } - - if (unpackSizeDefined && unpackSize == 0){ - return LZMA.LZMA_RES_ERROR; - } - if (rep0 >= this.dictSize || !this.outWindow.checkDistance(rep0)){ - return LZMA.LZMA_RES_ERROR; - } - } - len += LZMA.kMatchMinLen; - var isError:boolean = false; - if (unpackSizeDefined && unpackSize < len) - { - len = unpackSize; - isError = true; - } - this.outWindow.copyMatch(rep0 + 1, len); - unpackSize -= len; - if (isError){ - return LZMA.LZMA_RES_ERROR; - } - } - } - } - -} \ No newline at end of file diff --git a/src/lzma/OutWindow.ts b/src/lzma/OutWindow.ts deleted file mode 100644 index f51ac7e..0000000 --- a/src/lzma/OutWindow.ts +++ /dev/null @@ -1,66 +0,0 @@ -module nid.utils -{ - /** - * LZMA Decoder - * @author Nidin Vinayakan | nidinthb@gmail.com - */ - - export class OutWindow - { - public totalPos:number; - public outStream:Uint8Array; - - private buf:Uint8Array; - private pos:number; - public out_pos:number; - private size:number; - private isFull:boolean; - - constructor(){ - this.out_pos = 0; - } - public create(dictSize:number)//UInt32 - { - this.buf = new Uint8Array(dictSize); - this.pos = 0; - this.size = dictSize; - this.isFull = false; - this.totalPos = 0; - } - - public putByte(b) - { - this.totalPos++; - this.buf[this.pos++] = b; - if (this.pos == this.size) - { - this.pos = 0; - this.isFull = true; - } - //this.outStream.writeUnsignedByte(b); - this.outStream[this.out_pos++] = b; - } - - public getByte(dist:number)//UInt32 - { - return this.buf[dist <= this.pos ? this.pos - dist : this.size - dist + this.pos]; - } - - public copyMatch(dist, len)//UInt32 ,unsigned byte - { - for (; len > 0; len--){ - this.putByte(this.getByte(dist)); - } - } - - public checkDistance(dist):boolean //UInt32 - { - return dist <= this.pos || this.isFull; - } - - public isEmpty():boolean - { - return this.pos == 0 && !this.isFull; - } - } -} \ No newline at end of file diff --git a/src/lzma/RangeDecoder.ts b/src/lzma/RangeDecoder.ts deleted file mode 100644 index b1feea6..0000000 --- a/src/lzma/RangeDecoder.ts +++ /dev/null @@ -1,149 +0,0 @@ -/// -module nid.utils -{ - /** - * LZMA Decoder - * @author Nidin Vinayakan | nidinthb@gmail.com - */ - import MEMORY = nid.utils.MEMORY; - - export class RangeDecoder - { - static kTopValue:number = (1 << 24); - - public inStream:Uint8Array; - public corrupted:boolean; - - public in_pos:number; - private range:number;//UInt32 - private code:number;//UInt32 - private rangeI:number = 0; - private codeI:number = 1; - private loc1:number = 2; - private loc2:number = 3; - private U32:Uint32Array; - private U16:Uint16Array; - - constructor(){ - this.in_pos = 13; - } - public isFinishedOK():boolean{ - return this.U32[this.codeI] == 0; - } - public init():void - { - this.U32 = new Uint32Array(4); - this.U16 = new Uint16Array(4); - this.corrupted = false; - - if (this.inStream[this.in_pos++] != 0){ - this.corrupted = true; - } - - this.U32[this.rangeI] = 0xFFFFFFFF; - this.U32[this.codeI] = 0; - - for (var i:number = 0; i < 4; i++){ - this.U32[this.codeI] = (this.U32[this.codeI] << 8) | this.inStream[this.in_pos++]; - } - - if (this.U32[this.codeI] == this.U32[this.rangeI]){ - this.corrupted = true; - } - } - - public normalize() - { - if (this.U32[this.rangeI] < RangeDecoder.kTopValue) - { - this.U32[this.rangeI] <<= 8; - this.U32[this.codeI] = (this.U32[this.codeI] << 8) | this.inStream[this.in_pos++]; - } - } - - public decodeDirectBits(numBits:number):number - { - this.U32[this.loc1] = 0;//UInt32 - do - { - this.U32[this.rangeI] >>>= 1; - this.U32[this.codeI] -= this.U32[this.rangeI]; - this.U32[this.loc2] = 0 - (this.U32[this.codeI] >>> 31); - this.U32[this.codeI] += this.U32[this.rangeI] & this.U32[this.loc2]; - - if (this.U32[this.codeI] == this.U32[this.rangeI]){ - this.corrupted = true; - } - - this.normalize(); - this.U32[this.loc1] <<= 1; - this.U32[this.loc1] += this.U32[this.loc2] + 1; - } - while (--numBits); - return this.U32[this.loc1]; - } - - public decodeBit(prob:Uint16Array,index:number):number - { - this.U16[0] = prob[index]; - //bound - this.U32[2] = (this.U32[0] >>> 11) * this.U16[0]; - //var symbol:number; - if (this.U32[1] < this.U32[2]) - { - this.U16[0] += ((1 << 11) - this.U16[0]) >>> 5; - this.U32[0] = this.U32[2]; - this.U16[1] = 0; - } - else - { - //v -= v >>> LZMA.kNumMoveBits; - this.U16[0] -= this.U16[0] >>> 5; - this.U32[1] -= this.U32[2]; - this.U32[0] -= this.U32[2]; - this.U16[1] = 1; - } - prob[index] = this.U16[0]; - //this.normalize(); - if (this.U32[0] < 16777216) - { - this.U32[0] <<= 8; - this.U32[1] = (this.U32[1] << 8) | this.inStream[this.in_pos++]; - } - return this.U16[1]; - } - /*public decodeBit(prob:Uint16Array,index:number):number - { - var v = prob[index]; - //bound - //this.U32[this.loc1] = (this.U32[this.rangeI] >>> 11) * v; - this.U32[this.loc1] = (this.U32[this.rangeI] >>> 11) * v; - var symbol:number; - if (this.U32[this.codeI] < this.U32[this.loc1]) - { - v += ((1 << 11) - v) >>> 5; - this.U32[this.rangeI] = this.U32[this.loc1]; - symbol = 0; - } - else - { - //v -= v >>> LZMA.kNumMoveBits; - v -= v >>> 5; - this.U32[this.codeI] -= this.U32[this.loc1]; - this.U32[this.rangeI] -= this.U32[this.loc1]; - symbol = 1; - } - prob[index] = v; - //this.normalize(); - if (this.U32[this.rangeI] < 16777216) - { - this.U32[this.rangeI] <<= 8; - this.U32[this.codeI] = (this.U32[this.codeI] << 8) | this.inStream[this.in_pos++]; - } - return symbol; - }*/ - - } -} - - diff --git a/src/nid/lzma/BitTreeDecoder.ts b/src/nid/lzma/BitTreeDecoder.ts new file mode 100644 index 0000000..8fda8f8 --- /dev/null +++ b/src/nid/lzma/BitTreeDecoder.ts @@ -0,0 +1,39 @@ +import {LZMA} from "./LZMA"; +import {RangeDecoder} from "./RangeDecoder"; +/** + * LZMA Decoder + * @author Nidin Vinayakan | nidinthb@gmail.com + */ +export class BitTreeDecoder { + public probs:Uint16Array; + private numBits:number; + + constructor(numBits) { + this.numBits = numBits; + this.probs = new Uint16Array(1 << this.numBits); + + } + + public init():void { + LZMA.INIT_PROBS(this.probs); + } + + public decode(rc:RangeDecoder):number { + var m:number = 1;//Uint16 + for (var i:number = 0; i < this.numBits; i++) + m = (m << 1) + rc.decodeBit(this.probs, m); + return m - (1 << this.numBits); + } + + public reverseDecode(rc:RangeDecoder):number { + return LZMA.BitTreeReverseDecode(this.probs, this.numBits, rc); + } + + static constructArray(numBits:number, len:number):Array { + var vec:BitTreeDecoder[] = []; + for (var i:number = 0; i < len; i++) { + vec[i] = new BitTreeDecoder(numBits); + } + return vec; + } +} \ No newline at end of file diff --git a/src/nid/lzma/LZMA.ts b/src/nid/lzma/LZMA.ts new file mode 100644 index 0000000..44a6bc4 --- /dev/null +++ b/src/nid/lzma/LZMA.ts @@ -0,0 +1,127 @@ +import {LzmaDecoder} from "./LzmaDecoder"; +import {RangeDecoder} from "./RangeDecoder"; +"use strict" +/** + * LZMA Decoder + * @author Nidin Vinayakan | nidinthb@gmail.com + * + */ + +export class LZMA { + static LZMA_DIC_MIN:number = (1 << 12); + static LZMA_RES_ERROR:number = 0; + static LZMA_RES_FINISHED_WITH_MARKER:number = 1; + static LZMA_RES_FINISHED_WITHOUT_MARKER:number = 2; + static kNumBitModelTotalBits:number = 11; + static kNumMoveBits:number = 5; + static PROB_INIT_VAL = ((1 << LZMA.kNumBitModelTotalBits) / 2);//1024 + static kNumPosBitsMax:number = 4; + + static kNumStates:number = 12; + static kNumLenToPosStates:number = 4; + static kNumAlignBits:number = 4; + static kStartPosModelIndex:number = 4; + static kEndPosModelIndex:number = 14; + static kNumFullDistances:number = (1 << (LZMA.kEndPosModelIndex >>> 1)); + static kMatchMinLen:number = 2; + + public decoder:LzmaDecoder; + public data:Uint8Array; + public ucdata:Uint8Array; + + //Local registers + private loc1:number; + private loc2:number; + + static INIT_PROBS(p:Uint16Array):void { + for (var i:number = 0; i < p.length; i++) { + p[i] = this.PROB_INIT_VAL; + } + } + + static BitTreeReverseDecode(probs, numBits:number, rc:RangeDecoder, offset:number = 0):number { + var m:number = 1; + var symbol:number = 0; + for (var i:number = 0; i < numBits; i++) { + var bit:number = rc.decodeBit(probs, offset + m); + m <<= 1; + m += bit; + symbol |= (bit << i); + } + return symbol; + } + + constructor() { + this.decoder = new LzmaDecoder(); + } + + public decode(data:Uint8Array):Uint8Array { + this.data = data; + //var header:Uint8Array = data.readUint8Array(13); + var header:Uint8Array = new Uint8Array(13); + var i:number;//int + for (i = 0; i < 13; i++) { + header[i] = data[i]; + } + + this.decoder.decodeProperties(header); + + console.log("\nlc=" + this.decoder.lc + ", lp=" + this.decoder.lp + ", pb=" + this.decoder.pb); + console.log("\nDictionary Size in properties = " + this.decoder.dictSizeInProperties); + console.log("\nDictionary Size for decoding = " + this.decoder.dictSize); + //return this.ucdata; + var unpackSize:number = 0;//UInt64 + var unpackSizeDefined:boolean = false; + for (i = 0; i < 8; i++) { + var b:number = header[5 + i]; + if (b != 0xFF) { + unpackSizeDefined = true; + } + unpackSize |= b << (8 * i); + } + + this.decoder.markerIsMandatory = !unpackSizeDefined; + + console.log("\n"); + if (unpackSizeDefined) { + console.log("Uncompressed Size : " + unpackSize + " bytes"); + } else { + console.log("End marker is expected\n"); + } + this.decoder.rangeDec.inStream = data; + console.log("\n"); + + this.decoder.create(); + // we support the streams that have uncompressed size and marker. + var res:number = this.decoder.decode(unpackSizeDefined, unpackSize); //int + + console.log("Read ", this.decoder.rangeDec.in_pos); + console.log("Written ", this.decoder.outWindow.out_pos); + + if (res == LZMA.LZMA_RES_ERROR) { + throw "LZMA decoding error"; + } + else if (res == LZMA.LZMA_RES_FINISHED_WITHOUT_MARKER) { + console.log("Finished without end marker"); + } + else if (res == LZMA.LZMA_RES_FINISHED_WITH_MARKER) { + if (unpackSizeDefined) { + if (this.decoder.outWindow.out_pos != unpackSize) { + throw "Finished with end marker before than specified size"; + } + console.log("Warning: "); + } + console.log("Finished with end marker"); + } + else { + throw "Internal Error"; + } + + console.log("\n"); + + if (this.decoder.rangeDec.corrupted) { + console.log("\nWarning: LZMA stream is corrupted\n"); + } + return this.decoder.outWindow.outStream; + } +} \ No newline at end of file diff --git a/src/nid/lzma/LZMAWorker.ts b/src/nid/lzma/LZMAWorker.ts new file mode 100644 index 0000000..27e83ab --- /dev/null +++ b/src/nid/lzma/LZMAWorker.ts @@ -0,0 +1,30 @@ +import {LZMA} from "./LZMA"; +"use strict"; +export class LZMAWorker { + static ENCODE:number = 1; + static DECODE:number = 2; + private decoder:LZMA; + private command:number = 0; + + constructor() { + var _this = this; + this.decoder = new LZMA(); + + addEventListener('message', (e:any) => { + if (_this.command == 0) { + _this.command = e.data; + } else if (_this.command == 1) { + _this.command = 0; + } else if (_this.command == 2) { + _this.decode(e.data); + } + }, false); + } + + private decode(data):void { + var result = this.decoder.decode(new Uint8Array(data)); + ( postMessage)(LZMAWorker.DECODE); + ( postMessage)(result.buffer, [result.buffer]); + } +} +var zlma_w = new LZMAWorker(); \ No newline at end of file diff --git a/src/nid/lzma/LenDecoder.ts b/src/nid/lzma/LenDecoder.ts new file mode 100644 index 0000000..a541732 --- /dev/null +++ b/src/nid/lzma/LenDecoder.ts @@ -0,0 +1,40 @@ +import {BitTreeDecoder} from "./BitTreeDecoder"; +import {LZMA} from "./LZMA"; +import {RangeDecoder} from "./RangeDecoder"; +/** + * LZMA Decoder + * @author Nidin Vinayakan | nidinthb@gmail.com + */ + +export class LenDecoder { + + private choice; + private lowCoder:Array;//3 + private midCoder:Array;//3 + private highCoder:BitTreeDecoder;//8 + + constructor() { + this.lowCoder = BitTreeDecoder.constructArray(3, 1 << LZMA.kNumPosBitsMax); + this.midCoder = BitTreeDecoder.constructArray(3, 1 << LZMA.kNumPosBitsMax); + this.highCoder = new BitTreeDecoder(8); + } + + public init():void { + this.choice = [LZMA.PROB_INIT_VAL, LZMA.PROB_INIT_VAL]; + this.highCoder.init(); + for (var i:number = 0; i < (1 << LZMA.kNumPosBitsMax); i++) { + this.lowCoder[i].init(); + this.midCoder[i].init(); + } + } + + public decode(rc:RangeDecoder, posState:number):number { + if (rc.decodeBit(this.choice, 0) == 0) { + return this.lowCoder[posState].decode(rc); + } + if (rc.decodeBit(this.choice, 1) == 0) { + return 8 + this.midCoder[posState].decode(rc); + } + return 16 + this.highCoder.decode(rc); + } +} \ No newline at end of file diff --git a/src/nid/lzma/LzmaDecoder.ts b/src/nid/lzma/LzmaDecoder.ts new file mode 100644 index 0000000..2c7fb86 --- /dev/null +++ b/src/nid/lzma/LzmaDecoder.ts @@ -0,0 +1,316 @@ +import {RangeDecoder} from "./RangeDecoder"; +import {OutWindow} from "./OutWindow"; +import {BitTreeDecoder} from "./BitTreeDecoder"; +import {LenDecoder} from "./LenDecoder"; +import {LZMA} from "./LZMA"; +import {MEMORY} from "../utils/MEMORY"; +/** + * LZMA Decoder + * @author Nidin Vinayakan | nidinthb@gmail.com + */ + + +export class LzmaDecoder { + //Public + public markerIsMandatory:boolean; + public rangeDec:RangeDecoder;//RangeDecoder + public outWindow:OutWindow;//OutWindow + public lc:number; + public pb:number; + public lp:number;//unsigned byte + public dictSize:number;//UInt32 + public dictSizeInProperties:number;//UInt32 + + //Private + private litProbs:Uint16Array; + + private posSlotDecoder:Array; + private alignDecoder:BitTreeDecoder; + private posDecoders:Uint16Array; + + private isMatch:Uint16Array; + private isRep:Uint16Array; + private isRepG0:Uint16Array; + private isRepG1:Uint16Array; + private isRepG2:Uint16Array; + private isRep0Long:Uint16Array; + + private lenDecoder:LenDecoder; + private repLenDecoder:LenDecoder; + + //Local registers + private loc1:number; + private loc2:number; + private matchBitI:number; + private matchByteI:number; + private bitI:number; + private symbolI:number; + private prevByteI:number; + private litStateI:number; + + constructor() { + this.posSlotDecoder = BitTreeDecoder.constructArray(6, LZMA.kNumLenToPosStates);//6 + this.alignDecoder = new BitTreeDecoder(LZMA.kNumAlignBits); + this.posDecoders = new Uint16Array(1 + LZMA.kNumFullDistances - LZMA.kEndPosModelIndex); + + this.isMatch = new Uint16Array(LZMA.kNumStates << LZMA.kNumPosBitsMax); + this.isRep = new Uint16Array(LZMA.kNumStates); + this.isRepG0 = new Uint16Array(LZMA.kNumStates); + this.isRepG1 = new Uint16Array(LZMA.kNumStates); + this.isRepG2 = new Uint16Array(LZMA.kNumStates); + this.isRep0Long = new Uint16Array(LZMA.kNumStates << LZMA.kNumPosBitsMax); + + this.lenDecoder = new LenDecoder(); + this.repLenDecoder = new LenDecoder(); + this.rangeDec = new RangeDecoder(); + this.outWindow = new OutWindow(); + } + + public init():void { + this.loc1 = MEMORY.getUint32() | 0; + this.loc2 = MEMORY.getUint32() | 0; + this.matchBitI = MEMORY.getUint16() | 0; + this.matchByteI = MEMORY.getUint16() | 0; + this.bitI = MEMORY.getUint16() | 0; + this.symbolI = MEMORY.getUint16() | 0; + this.prevByteI = MEMORY.getUint16() | 0; + this.litStateI = MEMORY.getUint16() | 0; + + this.initLiterals(); + this.initDist(); + + LZMA.INIT_PROBS(this.isMatch); + LZMA.INIT_PROBS(this.isRep); + LZMA.INIT_PROBS(this.isRepG0); + LZMA.INIT_PROBS(this.isRepG1); + LZMA.INIT_PROBS(this.isRepG2); + LZMA.INIT_PROBS(this.isRep0Long); + + this.lenDecoder.init(); + this.repLenDecoder.init(); + } + + public create():void { + this.outWindow.create(this.dictSize); + this.createLiterals(); + } + + //Private + private createLiterals():void { + this.litProbs = new Uint16Array(0x300 << (this.lc + this.lp)); + } + + private initLiterals():void { + var num:number = 0x300 << (this.lc + this.lp);//UInt32 + for (var i:number = 0; i < num; i++) { + this.litProbs[i] = LZMA.PROB_INIT_VAL; + } + } + + private decodeLiteral(state, rep0):void//unsigned , UInt32 + { + MEMORY.u16[this.prevByteI] = 0;//unsigned byte + if (!this.outWindow.isEmpty()) + MEMORY.u16[this.prevByteI] = this.outWindow.getByte(1); + + MEMORY.u16[this.symbolI] = 1; + MEMORY.u16[this.litStateI] = ((this.outWindow.totalPos & ((1 << this.lp) - 1)) << this.lc) + (MEMORY.u16[this.prevByteI] >>> (8 - this.lc)); + var probsOffset:number = (0x300 * MEMORY.u16[this.litStateI]) | 0; + + if (state >= 7) { + MEMORY.u16[this.matchByteI] = this.outWindow.getByte(rep0 + 1); + do + { + MEMORY.u16[this.matchBitI] = (MEMORY.u16[this.matchByteI] >>> 7) & 1; + MEMORY.u16[this.matchByteI] <<= 1; + MEMORY.u16[this.bitI] = this.rangeDec.decodeBit(this.litProbs, probsOffset + ((1 + MEMORY.u16[this.matchBitI]) << 8) + MEMORY.u16[this.symbolI]); + MEMORY.u16[this.symbolI] = (MEMORY.u16[this.symbolI] << 1) | MEMORY.u16[this.bitI]; + if (MEMORY.u16[this.matchBitI] != MEMORY.u16[this.bitI]) + break; + } + while (MEMORY.u16[this.symbolI] < 0x100); + } + while (MEMORY.u16[this.symbolI] < 0x100) { + MEMORY.u16[this.symbolI] = (MEMORY.u16[this.symbolI] << 1) | this.rangeDec.decodeBit(this.litProbs, probsOffset + MEMORY.u16[this.symbolI]); + } + this.outWindow.putByte(MEMORY.u16[this.symbolI] - 0x100); + } + + private decodeDistance(len):number//unsigned byte + { + var lenState:number = len;//unsigned byte + if (lenState > LZMA.kNumLenToPosStates - 1) + lenState = LZMA.kNumLenToPosStates - 1; + + var posSlot = this.posSlotDecoder[lenState].decode(this.rangeDec);//unsigned byte + if (posSlot < 4) + return posSlot; + + var numDirectBits = ((posSlot >>> 1) - 1);//unsigned byte + MEMORY.u32[this.loc1] = ((2 | (posSlot & 1)) << numDirectBits);//UInt32 + if (posSlot < LZMA.kEndPosModelIndex) { + MEMORY.u32[this.loc1] += LZMA.BitTreeReverseDecode(this.posDecoders, numDirectBits, this.rangeDec, MEMORY.u32[this.loc1] - posSlot); + } + else { + MEMORY.u32[this.loc1] += this.rangeDec.decodeDirectBits(numDirectBits - LZMA.kNumAlignBits) << LZMA.kNumAlignBits; + MEMORY.u32[this.loc1] += this.alignDecoder.reverseDecode(this.rangeDec); + } + return MEMORY.u32[this.loc1]; + } + + private initDist():void { + for (var i = 0; i < LZMA.kNumLenToPosStates; i++) { + this.posSlotDecoder[i].init(); + } + this.alignDecoder.init(); + LZMA.INIT_PROBS(this.posDecoders); + } + + public decodeProperties(properties:Uint8Array):void { + var prop = new Uint8Array(4); + prop[0] = properties[0]; + if (prop[0] >= (9 * 5 * 5)) { + throw "Incorrect LZMA properties"; + } + prop[1] = prop[0] % 9; + prop[0] /= 9; + prop[2] = prop[0] / 5; + prop[3] = prop[0] % 5; + + this.lc = prop[1]; + this.pb = prop[2]; + this.lp = prop[3]; + + this.dictSizeInProperties = 0; + for (var i:number = 0; i < 4; i++) { + this.dictSizeInProperties |= properties[i + 1] << (8 * i); + } + + this.dictSize = this.dictSizeInProperties; + + if (this.dictSize < LZMA.LZMA_DIC_MIN) { + this.dictSize = LZMA.LZMA_DIC_MIN; + } + } + + private updateState_Literal(state:number):number { + if (state < 4) return 0; + else if (state < 10) return state - 3; + else return state - 6; + } + + private updateState_ShortRep(state:number):number { + return state < 7 ? 9 : 11; + } + + private updateState_Rep(state:number):number { + return state < 7 ? 8 : 11; + } + + private updateState_Match(state:number):number { + return state < 7 ? 7 : 10; + } + + public decode(unpackSizeDefined:boolean, unpackSize:number):number//UInt64 + { + this.init(); + this.rangeDec.init(); + + if (unpackSizeDefined) { + this.outWindow.outStream = new Uint8Array(new ArrayBuffer(unpackSize)); + } + + var rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0;//UInt32 + var state = 0;//unsigned byte + + for (; ;) { + if (unpackSizeDefined && unpackSize == 0 && !this.markerIsMandatory) { + if (this.rangeDec.isFinishedOK()) { + return LZMA.LZMA_RES_FINISHED_WITHOUT_MARKER; + } + } + + var posState = this.outWindow.totalPos & ((1 << this.pb) - 1); + + if (this.rangeDec.decodeBit(this.isMatch, (state << LZMA.kNumPosBitsMax) + posState) == 0) { + if (unpackSizeDefined && unpackSize == 0) { + return LZMA.LZMA_RES_ERROR; + } + this.decodeLiteral(state, rep0); + state = this.updateState_Literal(state); + unpackSize--; + continue; + } + + var len; + + if (this.rangeDec.decodeBit(this.isRep, state) != 0) { + if (unpackSizeDefined && unpackSize == 0) { + return LZMA.LZMA_RES_ERROR; + } + if (this.outWindow.isEmpty()) { + return LZMA.LZMA_RES_ERROR; + } + if (this.rangeDec.decodeBit(this.isRepG0, state) == 0) { + if (this.rangeDec.decodeBit(this.isRep0Long, (state << LZMA.kNumPosBitsMax) + posState) == 0) { + state = this.updateState_ShortRep(state); + this.outWindow.putByte(this.outWindow.getByte(rep0 + 1)); + unpackSize--; + continue; + } + } + else { + var dist:number; + if (this.rangeDec.decodeBit(this.isRepG1, state) == 0) { + dist = rep1; + } + else { + if (this.rangeDec.decodeBit(this.isRepG2, state) == 0) { + dist = rep2; + } + else { + dist = rep3; + rep3 = rep2; + } + rep2 = rep1; + } + rep1 = rep0; + rep0 = dist; + } + len = this.repLenDecoder.decode(this.rangeDec, posState); + state = this.updateState_Rep(state); + } + else { + rep3 = rep2; + rep2 = rep1; + rep1 = rep0; + len = this.lenDecoder.decode(this.rangeDec, posState); + state = this.updateState_Match(state); + rep0 = this.decodeDistance(len); + if (rep0 == 0xFFFFFFFF) { + return this.rangeDec.isFinishedOK() ? + LZMA.LZMA_RES_FINISHED_WITH_MARKER : + LZMA.LZMA_RES_ERROR; + } + + if (unpackSizeDefined && unpackSize == 0) { + return LZMA.LZMA_RES_ERROR; + } + if (rep0 >= this.dictSize || !this.outWindow.checkDistance(rep0)) { + return LZMA.LZMA_RES_ERROR; + } + } + len += LZMA.kMatchMinLen; + var isError:boolean = false; + if (unpackSizeDefined && unpackSize < len) { + len = unpackSize; + isError = true; + } + this.outWindow.copyMatch(rep0 + 1, len); + unpackSize -= len; + if (isError) { + return LZMA.LZMA_RES_ERROR; + } + } + } +} \ No newline at end of file diff --git a/src/nid/lzma/OutWindow.ts b/src/nid/lzma/OutWindow.ts new file mode 100644 index 0000000..cd0fd36 --- /dev/null +++ b/src/nid/lzma/OutWindow.ts @@ -0,0 +1,60 @@ +/** + * LZMA Decoder + * @author Nidin Vinayakan | nidinthb@gmail.com + */ + +export class OutWindow { + public totalPos:number; + public outStream:Uint8Array; + + private buf:Uint8Array; + private pos:number; + public out_pos:number; + private size:number; + private isFull:boolean; + + constructor() { + this.out_pos = 0; + } + + public create(dictSize:number)//UInt32 + { + this.buf = new Uint8Array(dictSize); + this.pos = 0; + this.size = dictSize; + this.isFull = false; + this.totalPos = 0; + } + + public putByte(b) { + this.totalPos++; + this.buf[this.pos++] = b; + if (this.pos == this.size) { + this.pos = 0; + this.isFull = true; + } + //this.outStream.writeUnsignedByte(b); + this.outStream[this.out_pos++] = b; + } + + public getByte(dist:number)//UInt32 + { + return this.buf[dist <= this.pos ? this.pos - dist : this.size - dist + this.pos]; + } + + public copyMatch(dist, len)//UInt32 ,unsigned byte + { + for (; len > 0; len--) { + this.putByte(this.getByte(dist)); + } + } + + public checkDistance(dist):boolean //UInt32 + { + return dist <= this.pos || this.isFull; + } + + public isEmpty():boolean { + return this.pos == 0 && !this.isFull; + } +} \ No newline at end of file diff --git a/src/nid/lzma/RangeDecoder.ts b/src/nid/lzma/RangeDecoder.ts new file mode 100644 index 0000000..7709513 --- /dev/null +++ b/src/nid/lzma/RangeDecoder.ts @@ -0,0 +1,136 @@ +/** + * LZMA Decoder + * @author Nidin Vinayakan | nidinthb@gmail.com + */ + +export class RangeDecoder { + static kTopValue:number = (1 << 24); + + public inStream:Uint8Array; + public corrupted:boolean; + + public in_pos:number; + private range:number;//UInt32 + private code:number;//UInt32 + private rangeI:number = 0; + private codeI:number = 1; + private loc1:number = 2; + private loc2:number = 3; + private U32:Uint32Array; + private U16:Uint16Array; + + constructor() { + this.in_pos = 13; + } + + public isFinishedOK():boolean { + return this.U32[this.codeI] == 0; + } + + public init():void { + this.U32 = new Uint32Array(4); + this.U16 = new Uint16Array(4); + this.corrupted = false; + + if (this.inStream[this.in_pos++] != 0) { + this.corrupted = true; + } + + this.U32[this.rangeI] = 0xFFFFFFFF; + this.U32[this.codeI] = 0; + + for (var i:number = 0; i < 4; i++) { + this.U32[this.codeI] = (this.U32[this.codeI] << 8) | this.inStream[this.in_pos++]; + } + + if (this.U32[this.codeI] == this.U32[this.rangeI]) { + this.corrupted = true; + } + } + + public normalize() { + if (this.U32[this.rangeI] < RangeDecoder.kTopValue) { + this.U32[this.rangeI] <<= 8; + this.U32[this.codeI] = (this.U32[this.codeI] << 8) | this.inStream[this.in_pos++]; + } + } + + public decodeDirectBits(numBits:number):number { + this.U32[this.loc1] = 0;//UInt32 + do + { + this.U32[this.rangeI] >>>= 1; + this.U32[this.codeI] -= this.U32[this.rangeI]; + this.U32[this.loc2] = 0 - (this.U32[this.codeI] >>> 31); + this.U32[this.codeI] += this.U32[this.rangeI] & this.U32[this.loc2]; + + if (this.U32[this.codeI] == this.U32[this.rangeI]) { + this.corrupted = true; + } + + this.normalize(); + this.U32[this.loc1] <<= 1; + this.U32[this.loc1] += this.U32[this.loc2] + 1; + } + while (--numBits); + return this.U32[this.loc1]; + } + + public decodeBit(prob:Uint16Array, index:number):number { + this.U16[0] = prob[index]; + //bound + this.U32[2] = (this.U32[0] >>> 11) * this.U16[0]; + //var symbol:number; + if (this.U32[1] < this.U32[2]) { + this.U16[0] += ((1 << 11) - this.U16[0]) >>> 5; + this.U32[0] = this.U32[2]; + this.U16[1] = 0; + } + else { + //v -= v >>> LZMA.kNumMoveBits; + this.U16[0] -= this.U16[0] >>> 5; + this.U32[1] -= this.U32[2]; + this.U32[0] -= this.U32[2]; + this.U16[1] = 1; + } + prob[index] = this.U16[0]; + //this.normalize(); + if (this.U32[0] < 16777216) { + this.U32[0] <<= 8; + this.U32[1] = (this.U32[1] << 8) | this.inStream[this.in_pos++]; + } + return this.U16[1]; + } + + /*public decodeBit(prob:Uint16Array,index:number):number + { + var v = prob[index]; + //bound + //this.U32[this.loc1] = (this.U32[this.rangeI] >>> 11) * v; + this.U32[this.loc1] = (this.U32[this.rangeI] >>> 11) * v; + var symbol:number; + if (this.U32[this.codeI] < this.U32[this.loc1]) + { + v += ((1 << 11) - v) >>> 5; + this.U32[this.rangeI] = this.U32[this.loc1]; + symbol = 0; + } + else + { + //v -= v >>> LZMA.kNumMoveBits; + v -= v >>> 5; + this.U32[this.codeI] -= this.U32[this.loc1]; + this.U32[this.rangeI] -= this.U32[this.loc1]; + symbol = 1; + } + prob[index] = v; + //this.normalize(); + if (this.U32[this.rangeI] < 16777216) + { + this.U32[this.rangeI] <<= 8; + this.U32[this.codeI] = (this.U32[this.codeI] << 8) | this.inStream[this.in_pos++]; + } + return symbol; + }*/ + +} \ No newline at end of file diff --git a/src/nid/utils/AMFHelper.ts b/src/nid/utils/AMFHelper.ts new file mode 100644 index 0000000..5518c58 --- /dev/null +++ b/src/nid/utils/AMFHelper.ts @@ -0,0 +1,653 @@ +/* +/!** + * JavaScript AMF Serializer + * version : 0.1 + * @author Nidin Vinayakan | nidinthb@gmail.com + * + *!/ + +export class AMFHelper { + /!** + * AMF 3 Encoding and Decoding + *!/ + + // AMF marker constants + private UNDEFINED_TYPE = 0; + private NULL_TYPE = 1; + private FALSE_TYPE = 2; + private TRUE_TYPE = 3; + private INTEGER_TYPE = 4; + private DOUBLE_TYPE = 5; + private STRING_TYPE = 6; + private XML_DOC_TYPE = 7; + private DATE_TYPE = 8; + private ARRAY_TYPE = 9; + private OBJECT_TYPE = 10; + private XML_TYPE = 11; + private BYTE_ARRAY_TYPE = 12; + + // AbstractMessage Serialization Constants + private HAS_NEXT_FLAG = 128; + private BODY_FLAG = 1; + private CLIENT_ID_FLAG = 2; + private DESTINATION_FLAG = 4; + private HEADERS_FLAG = 8; + private MESSAGE_ID_FLAG = 16; + private TIMESTAMP_FLAG = 32; + private TIME_TO_LIVE_FLAG = 64; + private CLIENT_ID_BYTES_FLAG = 1; + private MESSAGE_ID_BYTES_FLAG = 2; + + //AsyncMessage Serialization Constants + private CORRELATION_ID_FLAG = 1; + private CORRELATION_ID_BYTES_FLAG = 2; + + // CommandMessage Serialization Constants + private OPERATION_FLAG = 1; + + private CLASS_ALIAS_REGISTRY = { + "DSK": "flex.messaging.messages.AcknowledgeMessageExt", + "DSA": "flex.messaging.messages.AsyncMessageExt", + "DSC": "flex.messaging.messages.CommandMessageExt" + }; + + private Flex = null; + + private initFlex():void { + // Abstract Message // + this.Flex.AbstractMessage = function () { + this.clientId = null; // object + this.destination = null; // string + this.messageId = null; // string + this.timestamp = null; // number + this.timeToLive = null; // number + + this.headers = null; // Map + this.body = null; // object + + //this.clientIdBytes; // byte array + //this.messageIdBytes; // byte array + }; + + this.Flex.AbstractMessage.prototype = { + + readExternal: function (ba, parser) { + var flagsArray = this.readFlags(ba); + for (var i = 0; i < flagsArray.length; i++) { + var flags = flagsArray[i], + reservedPosition = 0; + console.log(i + '/' + flagsArray.length, flags) + if (i == 0) { + if ((flags & this.BODY_FLAG) != 0) this.readExternalBody(ba, parser); + if ((flags & this.CLIENT_ID_FLAG) != 0) this.clientId = parser.readData(ba); + if ((flags & this.DESTINATION_FLAG) != 0) this.destination = parser.readData(ba); + if ((flags & this.HEADERS_FLAG) != 0) this.headers = parser.readData(ba); + if ((flags & this.MESSAGE_ID_FLAG) != 0) this.messageId = parser.readData(ba); + if ((flags & this.TIMESTAMP_FLAG) != 0) this.timestamp = parser.readData(ba); + if ((flags & this.TIME_TO_LIVE_FLAG) != 0) this.timeToLive = parser.readData(ba); + reservedPosition = 7; + } else if (i == 1) { + if ((flags & this.CLIENT_ID_BYTES_FLAG) != 0) { + var clientIdBytes = parser.readData(ba); + this.clientId = this.UUIDUtils.fromByteArray(clientIdBytes); + } + + if ((flags & this.MESSAGE_ID_BYTES_FLAG) != 0) { + var messageIdBytes = parser.readData(ba); + this.messageId = this.UUIDUtils.fromByteArray(messageIdBytes); + } + + reservedPosition = 2; + } + + // For forwards compatibility, read in any other flagged objects to + // preserve the integrity of the input stream... + if ((flags >> reservedPosition) != 0) { + for (var j = reservedPosition; j < 6; j++) { + if (((flags >> j) & 1) != 0) parser.readData(ba); + } + } + } + + return this; + }, + + readExternalBody: function (ba, parser) { + this.body = parser.readData(ba); + }, + + readFlags: function (ba) { + var hasNextFlag = true, + flagsArray = [], + i = 0; + + while (hasNextFlag) { + var flags = ba.readUnsignedByte(); + /!*if (i == flagsArray.length) { + short[] tempArray = new short[i*2]; + System.arraycopy(flagsArray, 0, tempArray, 0, flagsArray.length); + flagsArray = tempArray; + }*!/ + + flagsArray[i] = flags; + hasNextFlag = ((flags & this.HAS_NEXT_FLAG) != 0) ? true : false; + i++; + } + + return flagsArray; + } + }; + + // flex.messaging.messages.AsyncMessage // + this.Flex.AsyncMessage = function () { + this.correlationId = null; // string + //var correlationIdBytes; // byte array + }; + this.Flex.AsyncMessage.prototype = new this.Flex.AbstractMessage(); + this.Flex.AsyncMessage.constructor = this.Flex.AsyncMessage; + + this.Flex.AsyncMessage.prototype.readExternal = function (ba, parser) { + this.Flex.AbstractMessage.prototype.readExternal.call(this, ba, parser); + + var flagsArray = this.readFlags(ba); + for (var i = 0; i < flagsArray.length; i++) { + var flags = flagsArray[i], + reservedPosition = 0; + + if (i == 0) { + if ((flags & this.CORRELATION_ID_FLAG) != 0) this.correlationId = parser.readData(ba); + + if ((flags & this.CORRELATION_ID_BYTES_FLAG) != 0) { + var correlationIdBytes = parser.readData(ba); + this.correlationId = this.UUIDUtils.fromByteArray(correlationIdBytes); + } + + reservedPosition = 2; + } + + // For forwards compatibility, read in any other flagged objects + // to preserve the integrity of the input stream... + if ((flags >> reservedPosition) != 0) { + for (var j = reservedPosition; j < 6; ++j) { + if (((flags >> j) & 1) != 0) parser.readData(ba); + } + } + } + + return this; + }; + + // DSA - flex.messaging.messages.AsyncMessageExt // + this.Flex.AsyncMessageExt = function () { + }; + this.Flex.AsyncMessageExt.prototype = new this.Flex.AsyncMessage(); + this.Flex.AsyncMessageExt.constructor = this.Flex.AsyncMessageExt; + + // flex.messaging.messages.AcknowledgeMessage // + this.Flex.AcknowledgeMessage = function () { + }; + this.Flex.AcknowledgeMessage.prototype = new this.Flex.AsyncMessage(); + this.Flex.AcknowledgeMessage.constructor = this.Flex.AcknowledgeMessage; + + this.Flex.AcknowledgeMessage.prototype.readExternal = function (ba, parser) { + this.Flex.AsyncMessage.prototype.readExternal.call(this, ba, parser); + + var flagsArray = this.readFlags(ba); + for (var i = 0; i < flagsArray.length; ++i) { + var flags = flagsArray[i], + reservedPosition = 0; + + // For forwards compatibility, read in any other flagged objects + // to preserve the integrity of the input stream... + if ((flags >> reservedPosition) != 0) { + for (var j = reservedPosition; j < 6; ++j) { + if (((flags >> j) & 1) != 0) parser.readData(ba); + } + } + } + + return this; + }; + + // DSK - flex.messaging.messages.AcknowledgeMessageExt // + this.Flex.AcknowledgeMessageExt = function () { + }; + this.Flex.AcknowledgeMessageExt.prototype = new this.Flex.AcknowledgeMessage(); + this.Flex.AcknowledgeMessageExt.constructor = this.Flex.AcknowledgeMessageExt; + + // flex.messaging.messages.CommandMessage // + this.Flex.CommandMessage = function () { + this.operation = 1000; + this.operationName = "unknown"; + }; + this.Flex.CommandMessage.prototype = new this.Flex.AsyncMessage(); + this.Flex.CommandMessage.constructor = this.Flex.CommandMessage; + + this.Flex.CommandMessage.prototype.readExternal = function (ba, parser) { + this.Flex.AsyncMessage.prototype.readExternal.call(this, ba, parser); + + var flagsArray = this.readFlags(ba); + for (var i = 0; i < flagsArray.length; ++i) { + var flags = flagsArray[i], + reservedPosition = 0, + operationNames = [ + "subscribe", "unsubscribe", "poll", "unused3", "client_sync", "client_ping", + "unused6", "cluster_request", "login", "logout", "subscription_invalidate", + "multi_subscribe", "disconnect", "trigger_connect" + ]; + + if (i == 0) { + if ((flags & this.OPERATION_FLAG) != 0) { + this.operation = parser.readData(ba); + if (this.operation < 0 || this.operation >= operationNames.length) { + this.operationName = "invalid." + this.operation + ""; + } else { + this.operationName = operationNames[this.operation]; + } + } + reservedPosition = 1; + } + + // For forwards compatibility, read in any other flagged objects + // to preserve the integrity of the input stream... + if ((flags >> reservedPosition) != 0) { + for (var j = reservedPosition; j < 6; ++j) { + if (((flags >> j) & 1) != 0) parser.readData(ba); + } + } + } + + return this; + }; + + // DSC - flex.messaging.messages.CommandMessageExt // + this.Flex.CommandMessageExt = function () { + }; + this.Flex.CommandMessageExt.prototype = new this.Flex.CommandMessage(); + this.Flex.CommandMessageExt.constructor = this.Flex.CommandMessageExt; + + // flex.messaging.messages.ErrorMessage // + this.Flex.ErrorMessage = function () { + this.faultCode = ''; + this.faultString = ''; + this.faultDetail = ''; + this.rootCause; + this.extendedData; + }; + this.Flex.ErrorMessage.prototype = new this.Flex.AcknowledgeMessage(); + this.Flex.ErrorMessage.constructor = this.Flex.ErrorMessage; + + // flex.messaging.messages.RPCPMessage // + this.Flex.RPCPMessage = function () { + this.remoteUsername = ''; + this.remotePassword = ''; + }; + this.Flex.RPCPMessage.prototype = new this.Flex.AbstractMessage(); + this.Flex.RPCPMessage.constructor = this.Flex.RPCPMessage; + + // flex.messaging.messages.HTTPMessage // + this.Flex.HTTPMessage = function () { + this.contentType = ''; + this.method = ''; + this.url = ''; + this.httpHeaders = {}; + this.recordHeaders = false; + }; + this.Flex.HTTPMessage.prototype = new this.Flex.RPCPMessage(); + this.Flex.HTTPMessage.constructor = this.Flex.HTTPMessage; + + // flex.messaging.messages.RemotingMessage // + this.Flex.RemotingMessage = function () { + this.operation = ''; + this.source = ''; + this.parameters = []; + this.parameterList = []; + }; + this.Flex.RemotingMessage.prototype = new this.Flex.RPCPMessage(); + this.Flex.RemotingMessage.constructor = this.Flex.RemotingMessage; + + // flex.messaging.messages.SOAPMessage // + this.Flex.SOAPMessage = function () { + this.remoteUsername = ''; + this.remotePassword = ''; + }; + this.Flex.SOAPMessage.prototype = new this.Flex.HTTPMessage(); + this.Flex.SOAPMessage.constructor = this.Flex.SOAPMessage; + + // flex.messaging.io.ArrayCollection // + this.Flex.ArrayCollection = function () { + this.source = null; + }; + this.Flex.ArrayCollection.prototype.readExternal = function (ba, parser) { + this.source = parser.readData(ba); + return this; + }; + + // Array List // + this.Flex.ArrayList = function () { + }; + this.Flex.ArrayList.prototype = new this.Flex.ArrayCollection(); + this.Flex.ArrayList.constructor = this.Flex.ArrayList; + + // flex.messaging.io.ObjectProxy // + this.Flex.ObjectProxy = function () { + }; + this.Flex.ObjectProxy.prototype.readExternal = function (ba, parser) { + var obj = parser.readData(ba); + for (var i in obj) { + this[i] = obj[i]; + } + return this; + }; + + // flex.messaging.io.ManagedObjectProxy // + this.Flex.ManagedObjectProxy = function () { + }; + this.Flex.ManagedObjectProxy.prototype = new this.Flex.ObjectProxy(); + this.Flex.ManagedObjectProxy.constructor = this.Flex.ManagedObjectProxy; + + // flex.messaging.io.SerializationProxy // + this.Flex.SerializationProxy = function () { + this.defaultInstance = null; + }; + + this.Flex.SerializationProxy.prototype.readExternal = function (ba, parser) { + /!*var saveObjectTable = null; + var saveTraitsTable = null; + var saveStringTable = null; + var in3 = null; + + if (ba instanceof Amf3Input) in3 = ba;*!/ + + try { + /!*if (in3 != null) { + saveObjectTable = in3.saveObjectTable(); + saveTraitsTable = in3.saveTraitsTable(); + saveStringTable = in3.saveStringTable(); + }*!/ + + this.defaultInstance = parser.readData(ba); + } finally { + /!*if (in3 != null) { + in3.restoreObjectTable(saveObjectTable); + in3.restoreTraitsTable(saveTraitsTable); + in3.restoreStringTable(saveStringTable); + }*!/ + } + + return this; + }; + } + + private readStringCache:Array = []; + private readTraitsCache:Array = []; + private readObjectCache:Array = []; + + private serialize():ArrayBuffer { + return null; + } + + private deserialize():any { + } + + private readAmfData():any { + if (this.Flex == null) { + this.initFlex(); + } + var type = this.readByte(); + switch (type) { + case this.UNDEFINED_TYPE : + return undefined; + case this.NULL_TYPE : + return null; + case this.FALSE_TYPE : + return false; + case this.TRUE_TYPE : + return true; + case this.INTEGER_TYPE : + return this.readInt(); + case this.DOUBLE_TYPE : + return this.readDouble(); + case this.STRING_TYPE : + return this.readString(); + case this.XML_DOC_TYPE : + return this.readXMLDoc(); + case this.DATE_TYPE : + return this.readDate(); + case this.ARRAY_TYPE : + return this.readArray(); + case this.OBJECT_TYPE : + return this.readAmfObject(); + case this.XML_TYPE : + return this.readXML(); + case this.BYTE_ARRAY_TYPE : + return this.readByteArray(); + default: + throw { + name: "Error", + message: "AMF3::readAmfData - Error : Undefined AMF3 type encountered '" + type + "'", + errorID: 0 + }; + } + } + + private getStringReference(index):string { + if (index >= this.readStringCache.length) { + console.log("AMF3::getStringReference - Error : Undefined string reference '" + index + "'"); + return null; + } + return this.readStringCache[index]; + } + + private getTraitReference(index):Object { + if (index >= this.readTraitsCache.length) { + console.log("AMF3::getTraitReference - Error : Undefined trait reference '" + index + "'"); + return null; + } + return this.readTraitsCache[index]; + } + + private getObjectReference(index):Object { + if (index >= this.readObjectCache.length) { + console.log("AMF3::getObjectReference - Error : Undefined object reference '" + index + "'"); + return null; + } + return this.readObjectCache[index]; + } + + private readU29():number { + var result = 0; + // Each byte must be treated as unsigned + var b = this.readUnsignedByte(); + + if (b < 128) return b; + + result = (b & 0x7F) << 7; + b = this.readUnsignedByte(); + + if (b < 128) return (result | b); + + result = (result | (b & 0x7F)) << 7; + b = this.readUnsignedByte(); + + if (b < 128) return (result | b); + + result = (result | (b & 0x7F)) << 8; + b = this.readUnsignedByte(); + + return (result | b); + } + + private readI29():number { + var result = this.readU29(); + // Symmetric with writing an integer to fix sign bits for negative values... + result = (result << 3) >> 3; + return result; + } + + private readString():string { + var refIndex = this.readU29(); + if ((refIndex & 1) == 0) return this.getStringReference(refIndex >> 1); + + // writeString() special cases the empty string + // to avoid creating a reference. + var len = refIndex >> 1; + var str = ""; + if (len > 0) { + str = this.readUTFBytes(len); + this.readStringCache.push(str); + } + return str; + } + + private readXMLDoc() { + var index = this.readU29(); + if ((index & 1) == 0) return this.getObjectReference(index >> 1); + + //var xmldoc = new XML(this.readUTFBytes(index >> 1)); + var xmldoc = this.readUTFBytes(index >> 1); + this.readObjectCache.push(xmldoc); + return xmldoc; + } + + private readDate() { + var index = this.readU29(); + if ((index & 1) == 0) return this.getObjectReference(index >> 1); + + var d = new Date(this.readDouble()); + this.readObjectCache.push(d); + return d; + } + + private readArray() { + var index = this.readU29(); + if ((index & 1) == 0) return this.getObjectReference(index >> 1); + + var arr = []; + this.readObjectCache.push(arr); + + // Associative values + var strKey = this.readString(); + while (strKey != "") { + arr[strKey] = this.readAmfData(); + strKey = this.readString(); + } + + // Strict values + var l = (index >> 1); + for (var i = 0; i < l; i++) { + arr[i] = this.readAmfData(); + } + + return arr; + } + + private readAmfObject() { + var index = this.readU29(); + if ((index & 1) == 0) return this.getObjectReference(index >> 1); + + // Read traits + var traits; + if ((index & 3) == 1) { + traits = this.getTraitReference(index >> 2); + } else { + var isExternalizable:boolean = ((index & 4) == 4); + var isDynamic:boolean = ((index & 8) == 8); + var className:string = this.readString(); + + var classMemberCount:number = (index >> 4); + /!* uint29 *!/ + var classMembers:Array = []; + for (var i = 0; i < classMemberCount; ++i) { + classMembers.push(this.readString()); + } + if (className.length == 0) className = 'Object'; + traits = { + type: className, + members: classMembers, + count: classMemberCount, + externalizable: isExternalizable, + dynamic: isDynamic + }; + this.readTraitsCache.push(traits); + } + + // Check for any registered class aliases + var aliasedClass = this.CLASS_ALIAS_REGISTRY[traits.type]; + if (aliasedClass != null) traits.type = aliasedClass; + + var obj = {}; + + //Add to references as circular references may search for this object + this.readObjectCache.push(obj); + + if (traits.externalizable) { + // Read Externalizable + try { + if (traits.type.indexOf("flex.") == 0) { + // Try to get a class + var classParts = traits.type.split("."); + var unqualifiedClassName = classParts[(classParts.length - 1)]; + if (unqualifiedClassName && this.Flex[unqualifiedClassName]) { + var flexParser = new this.Flex[unqualifiedClassName](); + obj = flexParser.readExternal(this, this); + } else { + obj = this.readAmfData(); + } + } + } catch (e) { + console.log("AMF3::readObject - Error : Unable to read externalizable data type '" + traits.type + "' | " + e); + obj = "Unable to read externalizable data type '" + traits.type + "'"; + } + } else { + var l = traits.members.length; + var key; + + for (var j = 0; j < l; ++j) { + var val = this.readAmfData(); + key = traits.members[j]; + obj[key] = val; + } + + if (traits.dynamic) { + key = this.readString(); + while (key != "") { + var value = this.readAmfData(); + obj[key] = value; + key = this.readString(); + } + } + } + + if (traits) obj.__traits = traits; + + return obj; + } + + private readXML() { + var index = this.readU29(); + if ((index & 1) == 0) return this.getObjectReference(index >> 1); + + //var xml = new XML(this.readUTFBytes(index >> 1)); + var xml = this.readUTFBytes(index >> 1); + this.readObjectCache.push(xml); + return xml; + } + + private readByteArray() { + var index = this.readU29(); + if ((index & 1) == 0) return this.getObjectReference(index >> 1); + + var len = (index >> 1); + //var ba2 = new DataArray(); + var ba2 = new DataArray(new ArrayBuffer(len)); + /!*while(len--) { + var b = this.readUnsignedByte().toString(16).toUpperCase(); + if (b.length < 2) b = '0' + b; + ba2.push('0x' + b); + }*!/ + this.readBytes(ba2, 0, len); + this.readObjectCache.push(ba2); + return ba2; + } +}*/ diff --git a/src/nid/utils/BitArray.ts b/src/nid/utils/BitArray.ts new file mode 100644 index 0000000..4072106 --- /dev/null +++ b/src/nid/utils/BitArray.ts @@ -0,0 +1,100 @@ +import {ByteArray} from "./ByteArray"; +/** + * JavaScript BitArray + * version : 0.2 + * @author Nidin Vinayakan | nidinthb@gmail.com + * + * Utility to read bits from ByteArray + */ +export class BitArray extends ByteArray { + private bitsPending:number = 0; + + constructor(buffer?:ArrayBuffer) { + super(buffer); + } + + public readBits(bits:number, bitBuffer:number = 0):number { + if (bits == 0) { + return bitBuffer; + } + var partial:number; + var bitsConsumed:number; + if (this.bitsPending > 0) { + var _byte:number = this[this.position - 1] & (0xff >> (8 - this.bitsPending)); + bitsConsumed = Math.min(this.bitsPending, bits); + this.bitsPending -= bitsConsumed; + partial = _byte >> this.bitsPending; + } else { + bitsConsumed = Math.min(8, bits); + this.bitsPending = 8 - bitsConsumed; + partial = this.readUnsignedByte() >> this.bitsPending; + } + bits -= bitsConsumed; + bitBuffer = (bitBuffer << bitsConsumed) | partial; + return (bits > 0) ? this.readBits(bits, bitBuffer) : bitBuffer; + } + + public writeBits(bits:number, value:number) { + if (bits == 0) { + return; + } + value &= (0xffffffff >>> (32 - bits)); + var bitsConsumed:number; + if (this.bitsPending > 0) { + if (this.bitsPending > bits) { + this[this.position - 1] |= value << (this.bitsPending - bits); + bitsConsumed = bits; + this.bitsPending -= bits; + } else if (this.bitsPending == bits) { + this[this.position - 1] |= value; + bitsConsumed = bits; + this.bitsPending = 0; + } else { + this[this.position - 1] |= value >> (bits - this.bitsPending); + bitsConsumed = this.bitsPending; + this.bitsPending = 0; + } + } else { + bitsConsumed = Math.min(8, bits); + this.bitsPending = 8 - bitsConsumed; + this.writeByte((value >> (bits - bitsConsumed)) << this.bitsPending); + } + bits -= bitsConsumed; + if (bits > 0) { + this.writeBits(bits, value); + } + } + + public resetBitsPending() { + this.bitsPending = 0; + } + + public calculateMaxBits(signed:boolean, values:Array):number { + var b:number = 0; + var vmax:number = -2147483648//int.MIN_VALUE; + if (!signed) { + for (var usvalue in values) { + b |= usvalue; + } + } else { + for (var svalue in values) { + if (svalue >= 0) { + b |= svalue; + } else { + b |= ~svalue << 1; + } + if (vmax < svalue) { + vmax = svalue; + } + } + } + var bits:number = 0; + if (b > 0) { + bits = b.toString(2).length; + if (signed && vmax > 0 && vmax.toString(2).length >= bits) { + bits++; + } + } + return bits; + } +} \ No newline at end of file diff --git a/src/nid/utils/ByteArray.ts b/src/nid/utils/ByteArray.ts new file mode 100644 index 0000000..5521377 --- /dev/null +++ b/src/nid/utils/ByteArray.ts @@ -0,0 +1,1090 @@ +import {Int64} from "../../ctypes/Int64"; +import {UInt64} from "../../ctypes/UInt64"; +/** + * JavaScript ByteArray + * version : 0.2 + * @author Nidin Vinayakan | nidinthb@gmail.com + * + * ActionScript3 ByteArray implementation in JavaScript + * limitation : size of ByteArray cannot be changed + * + */ +export class ByteArray { + static BIG_ENDIAN:string = "bigEndian"; + static LITTLE_ENDIAN:string = "littleEndian"; + + static SIZE_OF_BOOLEAN:number = 1; + static SIZE_OF_INT8:number = 1; + static SIZE_OF_INT16:number = 2; + static SIZE_OF_INT32:number = 4; + static SIZE_OF_INT64:number = 8; + static SIZE_OF_UINT8:number = 1; + static SIZE_OF_UINT16:number = 2; + static SIZE_OF_UINT32:number = 4; + static SIZE_OF_UINT64:number = 8; + static SIZE_OF_FLOAT32:number = 4; + static SIZE_OF_FLOAT64:number = 8; + + private BUFFER_EXT_SIZE:number = 1024;//Buffer expansion size + + public array:Uint8Array = null; + public data:DataView; + private _position:number; + public write_position:number; + public endian:string; + + constructor(buffer?:ArrayBuffer, offset:number = 0, length:number = 0) { + + if (buffer == undefined) { + buffer = new ArrayBuffer(this.BUFFER_EXT_SIZE); + this.write_position = 0; + } + else if (buffer == null) { + this.write_position = 0; + } else { + this.write_position = length > 0 ? length : buffer.byteLength; + } + if (buffer) { + this.data = new DataView(buffer, offset, length > 0 ? length : buffer.byteLength); + } + this._position = 0; + this.endian = ByteArray.BIG_ENDIAN; + } + + // getter setter + get buffer():ArrayBuffer { + return this.data.buffer; + } + + set buffer(value:ArrayBuffer) { + this.data = new DataView(value); + } + + get dataView():DataView { + return this.data; + } + + set dataView(value:DataView) { + this.data = value; + this.write_position = value.byteLength; + } + + get phyPosition():number { + return this._position + this.data.byteOffset; + } + + get bufferOffset():number { + return this.data.byteOffset; + } + + get position():number { + return this._position; + } + + set position(value:number) { + if (this._position < value) { + if (!this.validate(this._position - value)) { + return; + } + } + this._position = value; + this.write_position = value > this.write_position ? value : this.write_position; + } + + get length():number { + return this.write_position; + } + + set length(value:number) { + this.validateBuffer(value); + } + + get bytesAvailable():number { + return this.data.byteLength - this._position; + } + + //end + public clear():void { + this._position = 0; + } + + public getArray():Uint8Array { + if (this.array == null) { + this.array = new Uint8Array(this.data.buffer, this.data.byteOffset, this.data.byteLength); + } + return this.array; + } + + public setArray(array:Uint8Array):void { + this.array = array; + this.setBuffer(array.buffer, array.byteOffset, array.byteLength); + } + + public setBuffer(buffer:ArrayBuffer, offset:number = 0, length:number = 0) { + if (buffer) { + this.data = new DataView(buffer, offset, length > 0 ? length : buffer.byteLength); + this.write_position = length > 0 ? length : buffer.byteLength; + } else { + this.write_position = 0; + } + this._position = 0; + } + + /** + * Reads a Boolean value from the byte stream. A single byte is read, + * and true is returned if the byte is nonzero, + * false otherwise. + * @return Returns true if the byte is nonzero, false otherwise. + */ + public readBoolean():boolean { + if (!this.validate(ByteArray.SIZE_OF_BOOLEAN)) return null; + + return this.data.getUint8(this.position++) != 0; + } + + /** + * Reads a signed byte from the byte stream. + * The returned value is in the range -128 to 127. + * @return An integer between -128 and 127. + */ + public readByte():number { + if (!this.validate(ByteArray.SIZE_OF_INT8)) return null; + + return this.data.getInt8(this.position++); + } + + /** + * Reads the number of data bytes, specified by the length parameter, from the byte stream. + * The bytes are read into the ByteArray object specified by the bytes parameter, + * and the bytes are written into the destination ByteArray starting at the _position specified by offset. + * @param bytes The ByteArray object to read data into. + * @param offset The offset (_position) in bytes at which the read data should be written. + * @param length The number of bytes to read. The default value of 0 causes all available data to be read. + */ + public readBytes(_bytes:ByteArray = null, offset:number = 0, length:number = 0, createNewBuffer:boolean = false):ByteArray { + if (length == 0) { + length = this.bytesAvailable; + } + else if (!this.validate(length)) return null; + + if (createNewBuffer) { + _bytes = _bytes == null ? new ByteArray(new ArrayBuffer(length)) : _bytes; + //This method is expensive + for (var i = 0; i < length; i++) { + _bytes.data.setUint8(i + offset, this.data.getUint8(this.position++)); + } + } else { + //Offset argument ignored + _bytes = _bytes == null ? new ByteArray(null) : _bytes; + _bytes.dataView = new DataView(this.data.buffer, this.bufferOffset + this.position, length); + this.position += length; + } + + return _bytes; + } + + /** + * Reads an IEEE 754 double-precision (64-bit) floating-point number from the byte stream. + * @return A double-precision (64-bit) floating-point number. + */ + public readDouble():number { + if (!this.validate(ByteArray.SIZE_OF_FLOAT64)) return null; + + var value:number = this.data.getFloat64(this.position, this.endian == ByteArray.LITTLE_ENDIAN); + this.position += ByteArray.SIZE_OF_FLOAT64; + return value; + } + + /** + * Reads an IEEE 754 single-precision (32-bit) floating-point number from the byte stream. + * @return A single-precision (32-bit) floating-point number. + */ + public readFloat():number { + if (!this.validate(ByteArray.SIZE_OF_FLOAT32)) return null; + + var value:number = this.data.getFloat32(this.position, this.endian == ByteArray.LITTLE_ENDIAN); + this.position += ByteArray.SIZE_OF_FLOAT32; + return value; + } + + /** + * Reads a signed 32-bit integer from the byte stream. + * + * The returned value is in the range -2147483648 to 2147483647. + * @return A 32-bit signed integer between -2147483648 and 2147483647. + */ + public readInt():number { + if (!this.validate(ByteArray.SIZE_OF_INT32)) return null; + + var value = this.data.getInt32(this.position, this.endian == ByteArray.LITTLE_ENDIAN); + this.position += ByteArray.SIZE_OF_INT32; + return value; + } + + /** + * Reads a signed 64-bit integer from the byte stream. + * + * The returned value is in the range −(2^63) to 2^63 − 1 + * @return A 64-bit signed integer between −(2^63) to 2^63 − 1 + */ + public readInt64():Int64 { + if (!this.validate(ByteArray.SIZE_OF_UINT32)) return null; + + var low = this.data.getInt32(this.position, this.endian == ByteArray.LITTLE_ENDIAN); + this.position += ByteArray.SIZE_OF_INT32; + var high = this.data.getInt32(this.position, this.endian == ByteArray.LITTLE_ENDIAN); + this.position += ByteArray.SIZE_OF_INT32; + return new Int64(low, high); + } + + /** + * Reads a multibyte string of specified length from the byte stream using the + * specified character set. + * @param length The number of bytes from the byte stream to read. + * @param charSet The string denoting the character set to use to interpret the bytes. + * Possible character set strings include "shift-jis", "cn-gb", + * "iso-8859-1", and others. + * For a complete list, see Supported Character Sets. + * Note: If the value for the charSet parameter + * is not recognized by the current system, the application uses the system's default + * code page as the character set. For example, a value for the charSet parameter, + * as in myTest.readMultiByte(22, "iso-8859-01") that uses 01 instead of + * 1 might work on your development system, but not on another system. + * On the other system, the application will use the system's default code page. + * @return UTF-8 encoded string. + */ + public readMultiByte(length:number, charSet?:string):string { + if (!this.validate(length)) return null; + + return ""; + } + + /** + * Reads a signed 16-bit integer from the byte stream. + * + * The returned value is in the range -32768 to 32767. + * @return A 16-bit signed integer between -32768 and 32767. + */ + public readShort():number { + if (!this.validate(ByteArray.SIZE_OF_INT16)) return null; + + var value = this.data.getInt16(this.position, this.endian == ByteArray.LITTLE_ENDIAN); + this.position += ByteArray.SIZE_OF_INT16; + return value; + } + + /** + * Reads an unsigned byte from the byte stream. + * + * The returned value is in the range 0 to 255. + * @return A 32-bit unsigned integer between 0 and 255. + */ + public readUnsignedByte():number { + if (!this.validate(ByteArray.SIZE_OF_UINT8)) return null; + + return this.data.getUint8(this.position++); + } + + /** + * Reads an unsigned 32-bit integer from the byte stream. + * + * The returned value is in the range 0 to 4294967295. + * @return A 32-bit unsigned integer between 0 and 4294967295. + */ + public readUnsignedInt():number { + if (!this.validate(ByteArray.SIZE_OF_UINT32)) return null; + + var value = this.data.getUint32(this.position, this.endian == ByteArray.LITTLE_ENDIAN); + this.position += ByteArray.SIZE_OF_UINT32; + return value; + } + + /** + * Reads a variable sized unsigned integer (VX -> 16-bit or 32-bit) from the byte stream. + * + * A VX is written as a variable length 2- or 4-byte element. If the index value is less than 65,280 (0xFF00), + * then the index is written as an unsigned two-byte integer. Otherwise the index is written as an unsigned + * four byte integer with bits 24-31 set. When reading an index, if the first byte encountered is 255 (0xFF), + * then the four-byte form is being used and the first byte should be discarded or masked out. + * + * The returned value is in the range 0 to 65279 or 0 to 2147483647. + * @return A VX 16-bit or 32-bit unsigned integer between 0 to 65279 or 0 and 2147483647. + */ + public readVariableSizedUnsignedInt():number { + + var value:number; + var c = this.readUnsignedByte(); + if (c != 0xFF) { + value = c << 8; + c = this.readUnsignedByte(); + value |= c; + } + else { + c = this.readUnsignedByte(); + value = c << 16; + c = this.readUnsignedByte(); + value |= c << 8; + c = this.readUnsignedByte(); + value |= c; + } + return value; + } + + /** + * Fast read for WebGL since only Uint16 numbers are expected + */ + public readU16VX():number { + return (this.readUnsignedByte() << 8) | this.readUnsignedByte(); + } + + /** + * Reads an unsigned 64-bit integer from the byte stream. + * + * The returned value is in the range 0 to 2^64 − 1. + * @return A 64-bit unsigned integer between 0 and 2^64 − 1 + */ + public readUnsignedInt64():UInt64 { + if (!this.validate(ByteArray.SIZE_OF_UINT32)) return null; + + var low = this.data.getUint32(this.position, this.endian == ByteArray.LITTLE_ENDIAN); + this.position += ByteArray.SIZE_OF_UINT32; + var high = this.data.getUint32(this.position, this.endian == ByteArray.LITTLE_ENDIAN); + this.position += ByteArray.SIZE_OF_UINT32; + return new UInt64(low, high); + } + + /** + * Reads an unsigned 16-bit integer from the byte stream. + * + * The returned value is in the range 0 to 65535. + * @return A 16-bit unsigned integer between 0 and 65535. + */ + public readUnsignedShort():number { + if (!this.validate(ByteArray.SIZE_OF_UINT16)) return null; + + var value = this.data.getUint16(this.position, this.endian == ByteArray.LITTLE_ENDIAN); + this.position += ByteArray.SIZE_OF_UINT16; + return value; + } + + /** + * Reads a UTF-8 string from the byte stream. The string + * is assumed to be prefixed with an unsigned short indicating + * the length in bytes. + * @return UTF-8 encoded string. + */ + public readUTF():string { + if (!this.validate(ByteArray.SIZE_OF_UINT16)) return null; + + var length:number = this.data.getUint16(this.position, this.endian == ByteArray.LITTLE_ENDIAN); + this.position += ByteArray.SIZE_OF_UINT16; + + if (length > 0) { + return this.readUTFBytes(length); + } else { + return ""; + } + } + + /** + * Reads a sequence of UTF-8 bytes specified by the length + * parameter from the byte stream and returns a string. + * @param length An unsigned short indicating the length of the UTF-8 bytes. + * @return A string composed of the UTF-8 bytes of the specified length. + */ + public readUTFBytes(length:number):string { + if (!this.validate(length)) return null; + + var _bytes:Uint8Array = new Uint8Array(this.buffer, this.bufferOffset + this.position, length); + this.position += length; + /*var _bytes: Uint8Array = new Uint8Array(new ArrayBuffer(length)); + for (var i = 0; i < length; i++) { + _bytes[i] = this.data.getUint8(this.position++); + }*/ + return this.decodeUTF8(_bytes); + } + + public readStandardString(length:number):string { + if (!this.validate(length)) return null; + + var str:string = ""; + + for (var i = 0; i < length; i++) { + str += String.fromCharCode(this.data.getUint8(this.position++)); + } + return str; + } + + public readStringTillNull(keepEvenByte:boolean = true):string { + + var str:string = ""; + var num:number = 0; + while (this.bytesAvailable > 0) { + var _byte:number = this.data.getUint8(this.position++); + num++; + if (_byte != 0) { + str += String.fromCharCode(_byte); + } else { + if (keepEvenByte && num % 2 != 0) { + this.position++; + } + break; + } + } + return str; + } + + /** + * Writes a Boolean value. A single byte is written according to the value parameter, + * either 1 if true or 0 if false. + * @param value A Boolean value determining which byte is written. If the parameter is true, + * the method writes a 1; if false, the method writes a 0. + */ + public writeBoolean(value:boolean):void { + this.validateBuffer(ByteArray.SIZE_OF_BOOLEAN); + + this.data.setUint8(this.position++, value ? 1 : 0); + } + + /** + * Writes a byte to the byte stream. + * The low 8 bits of the + * parameter are used. The high 24 bits are ignored. + * @param value A 32-bit integer. The low 8 bits are written to the byte stream. + */ + public writeByte(value:number):void { + this.validateBuffer(ByteArray.SIZE_OF_INT8); + + this.data.setInt8(this.position++, value); + } + + public writeUnsignedByte(value:number):void { + this.validateBuffer(ByteArray.SIZE_OF_UINT8); + + this.data.setUint8(this.position++, value); + } + + /** + * Writes a sequence of length bytes from the + * specified byte array, bytes, + * starting offset(zero-based index) bytes + * into the byte stream. + * + * If the length parameter is omitted, the default + * length of 0 is used; the method writes the entire buffer starting at + * offset. + * If the offset parameter is also omitted, the entire buffer is + * written. If offset or length + * is out of range, they are clamped to the beginning and end + * of the bytes array. + * @param _bytes The ByteArray object. + * @param offset A zero-based index indicating the _position into the array to begin writing. + * @param length An unsigned integer indicating how far into the buffer to write. + */ + public writeBytes(_bytes:ByteArray, offset:number = 0, length:number = 0):void { + this.validateBuffer(length); + + var tmp_data = new DataView(_bytes.buffer); + for (var i = 0; i < _bytes.length; i++) { + this.data.setUint8(this.position++, tmp_data.getUint8(i)); + } + } + + /** + * Writes an IEEE 754 double-precision (64-bit) floating-point number to the byte stream. + * @param value A double-precision (64-bit) floating-point number. + */ + public writeDouble(value:number):void { + this.validateBuffer(ByteArray.SIZE_OF_FLOAT64); + + this.data.setFloat64(this.position, value, this.endian == ByteArray.LITTLE_ENDIAN); + this.position += ByteArray.SIZE_OF_FLOAT64; + } + + /** + * Writes an IEEE 754 single-precision (32-bit) floating-point number to the byte stream. + * @param value A single-precision (32-bit) floating-point number. + */ + public writeFloat(value:number):void { + this.validateBuffer(ByteArray.SIZE_OF_FLOAT32); + + this.data.setFloat32(this.position, value, this.endian == ByteArray.LITTLE_ENDIAN); + this.position += ByteArray.SIZE_OF_FLOAT32; + } + + /** + * Writes a 32-bit signed integer to the byte stream. + * @param value An integer to write to the byte stream. + */ + public writeInt(value:number):void { + this.validateBuffer(ByteArray.SIZE_OF_INT32); + + this.data.setInt32(this.position, value, this.endian == ByteArray.LITTLE_ENDIAN); + this.position += ByteArray.SIZE_OF_INT32; + } + + /** + * Writes a multibyte string to the byte stream using the specified character set. + * @param value The string value to be written. + * @param charSet The string denoting the character set to use. Possible character set strings + * include "shift-jis", "cn-gb", "iso-8859-1", and others. + * For a complete list, see Supported Character Sets. + */ + public writeMultiByte(value:string, charSet:string):void { + + } + + /** + * Writes a 16-bit integer to the byte stream. The low 16 bits of the parameter are used. + * The high 16 bits are ignored. + * @param value 32-bit integer, whose low 16 bits are written to the byte stream. + */ + public writeShort(value:number):void { + this.validateBuffer(ByteArray.SIZE_OF_INT16); + + this.data.setInt16(this.position, value, this.endian == ByteArray.LITTLE_ENDIAN); + this.position += ByteArray.SIZE_OF_INT16; + } + + public writeUnsignedShort(value:number):void { + this.validateBuffer(ByteArray.SIZE_OF_UINT16); + + this.data.setUint16(this.position, value, this.endian == ByteArray.LITTLE_ENDIAN); + this.position += ByteArray.SIZE_OF_UINT16; + } + + /** + * Writes a 32-bit unsigned integer to the byte stream. + * @param value An unsigned integer to write to the byte stream. + */ + public writeUnsignedInt(value:number):void { + this.validateBuffer(ByteArray.SIZE_OF_UINT32); + + this.data.setUint32(this.position, value, this.endian == ByteArray.LITTLE_ENDIAN); + this.position += ByteArray.SIZE_OF_UINT32; + } + + /** + * Writes a UTF-8 string to the byte stream. The length of the UTF-8 string in bytes + * is written first, as a 16-bit integer, followed by the bytes representing the + * characters of the string. + * @param value The string value to be written. + */ + public writeUTF(value:string):void { + var utf8bytes:Uint8Array = this.encodeUTF8(value); + var length:number = utf8bytes.length; + + this.validateBuffer(ByteArray.SIZE_OF_UINT16 + length); + + this.data.setUint16(this.position, length, this.endian === ByteArray.LITTLE_ENDIAN); + this.position += ByteArray.SIZE_OF_UINT16; + this.writeUint8Array(utf8bytes); + } + + /** + * Writes a UTF-8 string to the byte stream. Similar to the writeUTF() method, + * but writeUTFBytes() does not prefix the string with a 16-bit length word. + * @param value The string value to be written. + */ + public writeUTFBytes(value:string):void { + this.writeUint8Array(this.encodeUTF8(value)); + } + + public toString():string { + return "[ByteArray] length:" + this.length + ", bytesAvailable:" + this.bytesAvailable; + } + + /****************************/ + /* EXTRA JAVASCRIPT APIs */ + /****************************/ + + /** + * Writes a Uint8Array to the byte stream. + * @param _bytes The Uint8Array to be written. + */ + public writeUint8Array(_bytes:Uint8Array):void { + this.validateBuffer(this.position + _bytes.length); + + for (var i = 0; i < _bytes.length; i++) { + this.data.setUint8(this.position++, _bytes[i]); + } + } + + /** + * Writes a Uint16Array to the byte stream. + * @param _bytes The Uint16Array to be written. + */ + public writeUint16Array(_bytes:Uint16Array):void { + this.validateBuffer(this.position + _bytes.length); + + for (var i = 0; i < _bytes.length; i++) { + this.data.setUint16(this.position, _bytes[i], this.endian === ByteArray.LITTLE_ENDIAN); + this.position += ByteArray.SIZE_OF_UINT16; + } + } + + /** + * Writes a Uint32Array to the byte stream. + * @param _bytes The Uint32Array to be written. + */ + public writeUint32Array(_bytes:Uint32Array):void { + this.validateBuffer(this.position + _bytes.length); + + for (var i = 0; i < _bytes.length; i++) { + this.data.setUint32(this.position, _bytes[i], this.endian === ByteArray.LITTLE_ENDIAN); + this.position += ByteArray.SIZE_OF_UINT32; + } + } + + /** + * Writes a Int8Array to the byte stream. + * @param _bytes The Int8Array to be written. + */ + public writeInt8Array(_bytes:Int8Array):void { + this.validateBuffer(this.position + _bytes.length); + + for (var i = 0; i < _bytes.length; i++) { + this.data.setInt8(this.position++, _bytes[i]); + } + } + + /** + * Writes a Int16Array to the byte stream. + * @param _bytes The Int16Array to be written. + */ + public writeInt16Array(_bytes:Int16Array):void { + this.validateBuffer(this.position + _bytes.length); + + for (var i = 0; i < _bytes.length; i++) { + this.data.setInt16(this.position, _bytes[i], this.endian === ByteArray.LITTLE_ENDIAN); + this.position += ByteArray.SIZE_OF_INT16; + } + } + + /** + * Writes a Int32Array to the byte stream. + * @param _bytes The Int32Array to be written. + */ + public writeInt32Array(_bytes:Int32Array):void { + this.validateBuffer(this.position + _bytes.length); + + for (var i = 0; i < _bytes.length; i++) { + this.data.setInt32(this.position, _bytes[i], this.endian === ByteArray.LITTLE_ENDIAN); + this.position += ByteArray.SIZE_OF_INT32; + } + } + + /** + * Writes a Float32Array to the byte stream. + * @param _bytes The Float32Array to be written. + */ + public writeFloat32Array(_bytes:Float32Array):void { + this.validateBuffer(this.position + _bytes.length); + + for (var i = 0; i < _bytes.length; i++) { + this.data.setFloat32(this.position, _bytes[i], this.endian === ByteArray.LITTLE_ENDIAN); + this.position += ByteArray.SIZE_OF_FLOAT32; + } + } + + /** + * Writes a Float64Array to the byte stream. + * @param _bytes The Float64Array to be written. + */ + public writeFloat64Array(_bytes:Float64Array):void { + this.validateBuffer(this.position + _bytes.length); + + for (var i = 0; i < _bytes.length; i++) { + this.data.setFloat64(this.position, _bytes[i], this.endian === ByteArray.LITTLE_ENDIAN); + this.position += ByteArray.SIZE_OF_FLOAT64; + } + } + + /** + * Read a Uint8Array from the byte stream. + * @param length An unsigned short indicating the length of the Uint8Array. + */ + public readUint8Array(length:number, createNewBuffer:boolean = true):Uint8Array { + if (!this.validate(length)) return null; + if (!createNewBuffer) { + var result:Uint8Array = new Uint8Array(this.buffer, this.bufferOffset + this.position, length); + this.position += length; + } else { + result = new Uint8Array(new ArrayBuffer(length)); + for (var i = 0; i < length; i++) { + result[i] = this.data.getUint8(this.position); + this.position += ByteArray.SIZE_OF_UINT8; + } + } + return result; + } + + /** + * Read a Uint16Array from the byte stream. + * @param length An unsigned short indicating the length of the Uint16Array. + */ + public readUint16Array(length:number, createNewBuffer:boolean = true):Uint16Array { + var size:number = length * ByteArray.SIZE_OF_UINT16; + if (!this.validate(size)) return null; + if (!createNewBuffer) { + var result:Uint16Array = new Uint16Array(this.buffer, this.bufferOffset + this.position, length); + this.position += size; + } + else { + result = new Uint16Array(new ArrayBuffer(size)); + for (var i = 0; i < length; i++) { + result[i] = this.data.getUint16(this.position, this.endian === ByteArray.LITTLE_ENDIAN); + this.position += ByteArray.SIZE_OF_UINT16; + } + } + return result; + } + + /** + * Read a Uint32Array from the byte stream. + * @param length An unsigned short indicating the length of the Uint32Array. + */ + public readUint32Array(length:number, createNewBuffer:boolean = true):Uint32Array { + var size:number = length * ByteArray.SIZE_OF_UINT32; + if (!this.validate(size)) return null; + if (!createNewBuffer) { + var result:Uint32Array = new Uint32Array(this.buffer, this.bufferOffset + this.position, length); + this.position += size; + } + else { + result = new Uint32Array(new ArrayBuffer(size)); + for (var i = 0; i < length; i++) { + result[i] = this.data.getUint32(this.position, this.endian === ByteArray.LITTLE_ENDIAN); + this.position += ByteArray.SIZE_OF_UINT32; + } + } + return result; + } + + /** + * Read a Int8Array from the byte stream. + * @param length An unsigned short indicating the length of the Int8Array. + */ + public readInt8Array(length:number, createNewBuffer:boolean = true):Int8Array { + if (!this.validate(length)) return null; + if (!createNewBuffer) { + var result:Int8Array = new Int8Array(this.buffer, this.bufferOffset + this.position, length); + this.position += length; + } + else { + result = new Int8Array(new ArrayBuffer(length)); + for (var i = 0; i < length; i++) { + result[i] = this.data.getInt8(this.position); + this.position += ByteArray.SIZE_OF_INT8; + } + } + return result; + } + + /** + * Read a Int16Array from the byte stream. + * @param length An unsigned short indicating the length of the Int16Array. + */ + public readInt16Array(length:number, createNewBuffer:boolean = true):Int16Array { + var size:number = length * ByteArray.SIZE_OF_INT16; + if (!this.validate(size)) return null; + if (!createNewBuffer) { + var result:Int16Array = new Int16Array(this.buffer, this.bufferOffset + this.position, length); + this.position += size; + } + else { + result = new Int16Array(new ArrayBuffer(size)); + for (var i = 0; i < length; i++) { + result[i] = this.data.getInt16(this.position, this.endian === ByteArray.LITTLE_ENDIAN); + this.position += ByteArray.SIZE_OF_INT16; + } + } + return result; + } + + /** + * Read a Int32Array from the byte stream. + * @param length An unsigned short indicating the length of the Int32Array. + */ + public readInt32Array(length:number, createNewBuffer:boolean = true):Int32Array { + var size:number = length * ByteArray.SIZE_OF_INT32; + if (!this.validate(size)) return null; + if (!createNewBuffer) { + + if ((this.bufferOffset + this.position) % 4 == 0) { + var result:Int32Array = new Int32Array(this.buffer, this.bufferOffset + this.position, length); + this.position += size; + } else { + var tmp:Uint8Array = new Uint8Array(new ArrayBuffer(size)); + for (var i = 0; i < size; i++) { + tmp[i] = this.data.getUint8(this.position); + this.position += ByteArray.SIZE_OF_UINT8; + } + result = new Int32Array(tmp.buffer); + } + } + else { + result = new Int32Array(new ArrayBuffer(size)); + for (var i = 0; i < length; i++) { + result[i] = this.data.getInt32(this.position, this.endian === ByteArray.LITTLE_ENDIAN); + this.position += ByteArray.SIZE_OF_INT32; + } + } + return result; + } + + /** + * Read a Float32Array from the byte stream. + * @param length An unsigned short indicating the length of the Float32Array. + */ + public readFloat32Array(length:number, createNewBuffer:boolean = true):Float32Array { + var size:number = length * ByteArray.SIZE_OF_FLOAT32; + if (!this.validate(size)) return null; + if (!createNewBuffer) { + if ((this.bufferOffset + this.position) % 4 == 0) { + var result:Float32Array = new Float32Array(this.buffer, this.bufferOffset + this.position, length); + this.position += size; + } else { + var tmp:Uint8Array = new Uint8Array(new ArrayBuffer(size)); + for (var i = 0; i < size; i++) { + tmp[i] = this.data.getUint8(this.position); + this.position += ByteArray.SIZE_OF_UINT8; + } + result = new Float32Array(tmp.buffer); + } + } + else { + result = new Float32Array(new ArrayBuffer(size)); + + for (var i = 0; i < length; i++) { + result[i] = this.data.getFloat32(this.position, this.endian === ByteArray.LITTLE_ENDIAN); + this.position += ByteArray.SIZE_OF_FLOAT32; + } + } + return result; + } + + /** + * Read a Float64Array from the byte stream. + * @param length An unsigned short indicating the length of the Float64Array. + */ + public readFloat64Array(length:number, createNewBuffer:boolean = true):Float64Array { + var size:number = length * ByteArray.SIZE_OF_FLOAT64; + if (!this.validate(size)) return null; + if (!createNewBuffer) { + var result:Float64Array = new Float64Array(this.buffer, this.position, length); + this.position += size; + } else { + result = new Float64Array(new ArrayBuffer(size)); + for (var i = 0; i < length; i++) { + result[i] = this.data.getFloat64(this.position, this.endian === ByteArray.LITTLE_ENDIAN); + this.position += ByteArray.SIZE_OF_FLOAT64; + } + } + return result; + } + + public validate(len:number):boolean { + //len += this.data.byteOffset; + if (this.data.byteLength > 0 && this._position + len <= this.data.byteLength) { + return true; + } else { + throw 'Error #2030: End of file was encountered.'; + } + } + + /**********************/ + /* PRIVATE METHODS */ + /**********************/ + private validateBuffer(len:number):void { + this.write_position = len > this.write_position ? len : this.write_position; + if (this.data.byteLength < len) { + var tmp:Uint8Array = new Uint8Array(new ArrayBuffer(len + this.BUFFER_EXT_SIZE)); + tmp.set(new Uint8Array(this.data.buffer)); + this.data.buffer = tmp.buffer; + } + } + + /** + * UTF-8 Encoding/Decoding + */ + private encodeUTF8(str:string):Uint8Array { + var pos:number = 0; + var codePoints = this.stringToCodePoints(str); + var outputBytes = []; + + while (codePoints.length > pos) { + var code_point:number = codePoints[pos++]; + + if (this.inRange(code_point, 0xD800, 0xDFFF)) { + this.encoderError(code_point); + } + else if (this.inRange(code_point, 0x0000, 0x007f)) { + outputBytes.push(code_point); + } else { + var count, offset; + if (this.inRange(code_point, 0x0080, 0x07FF)) { + count = 1; + offset = 0xC0; + } else if (this.inRange(code_point, 0x0800, 0xFFFF)) { + count = 2; + offset = 0xE0; + } else if (this.inRange(code_point, 0x10000, 0x10FFFF)) { + count = 3; + offset = 0xF0; + } + + outputBytes.push(this.div(code_point, Math.pow(64, count)) + offset); + + while (count > 0) { + var temp = this.div(code_point, Math.pow(64, count - 1)); + outputBytes.push(0x80 + (temp % 64)); + count -= 1; + } + } + } + return new Uint8Array(outputBytes); + } + + private decodeUTF8(data:Uint8Array):string { + var fatal:boolean = false; + var pos:number = 0; + var result:string = ""; + var code_point:number; + var utf8_code_point = 0; + var utf8_bytes_needed = 0; + var utf8_bytes_seen = 0; + var utf8_lower_boundary = 0; + + while (data.length > pos) { + + var _byte = data[pos++]; + + if (_byte === this.EOF_byte) { + if (utf8_bytes_needed !== 0) { + code_point = this.decoderError(fatal); + } else { + code_point = this.EOF_code_point; + } + } else { + + if (utf8_bytes_needed === 0) { + if (this.inRange(_byte, 0x00, 0x7F)) { + code_point = _byte; + } else { + if (this.inRange(_byte, 0xC2, 0xDF)) { + utf8_bytes_needed = 1; + utf8_lower_boundary = 0x80; + utf8_code_point = _byte - 0xC0; + } else if (this.inRange(_byte, 0xE0, 0xEF)) { + utf8_bytes_needed = 2; + utf8_lower_boundary = 0x800; + utf8_code_point = _byte - 0xE0; + } else if (this.inRange(_byte, 0xF0, 0xF4)) { + utf8_bytes_needed = 3; + utf8_lower_boundary = 0x10000; + utf8_code_point = _byte - 0xF0; + } else { + this.decoderError(fatal); + } + utf8_code_point = utf8_code_point * Math.pow(64, utf8_bytes_needed); + code_point = null; + } + } else if (!this.inRange(_byte, 0x80, 0xBF)) { + utf8_code_point = 0; + utf8_bytes_needed = 0; + utf8_bytes_seen = 0; + utf8_lower_boundary = 0; + pos--; + code_point = this.decoderError(fatal, _byte); + } else { + + utf8_bytes_seen += 1; + utf8_code_point = utf8_code_point + (_byte - 0x80) * Math.pow(64, utf8_bytes_needed - utf8_bytes_seen); + + if (utf8_bytes_seen !== utf8_bytes_needed) { + code_point = null; + } else { + + var cp = utf8_code_point; + var lower_boundary = utf8_lower_boundary; + utf8_code_point = 0; + utf8_bytes_needed = 0; + utf8_bytes_seen = 0; + utf8_lower_boundary = 0; + if (this.inRange(cp, lower_boundary, 0x10FFFF) && !this.inRange(cp, 0xD800, 0xDFFF)) { + code_point = cp; + } else { + code_point = this.decoderError(fatal, _byte); + } + } + + } + } + //Decode string + if (code_point !== null && code_point !== this.EOF_code_point) { + if (code_point <= 0xFFFF) { + if (code_point > 0)result += String.fromCharCode(code_point); + } else { + code_point -= 0x10000; + result += String.fromCharCode(0xD800 + ((code_point >> 10) & 0x3ff)); + result += String.fromCharCode(0xDC00 + (code_point & 0x3ff)); + } + } + } + return result; + } + + private encoderError(code_point) { + throw 'EncodingError! The code point ' + code_point + ' could not be encoded.'; + } + + private decoderError(fatal, opt_code_point?):number { + if (fatal) { + throw 'DecodingError'; + } + return opt_code_point || 0xFFFD; + } + + private EOF_byte:number = -1; + private EOF_code_point:number = -1; + + private inRange(a, min, max) { + return min <= a && a <= max; + } + + private div(n, d) { + return Math.floor(n / d); + } + + private stringToCodePoints(string:string) { + /** @type {Array.} */ + var cps = []; + // Based on http://www.w3.org/TR/WebIDL/#idl-DOMString + var i = 0, n = string.length; + while (i < string.length) { + var c = string.charCodeAt(i); + if (!this.inRange(c, 0xD800, 0xDFFF)) { + cps.push(c); + } else if (this.inRange(c, 0xDC00, 0xDFFF)) { + cps.push(0xFFFD); + } else { // (inRange(c, 0xD800, 0xDBFF)) + if (i === n - 1) { + cps.push(0xFFFD); + } else { + var d = string.charCodeAt(i + 1); + if (this.inRange(d, 0xDC00, 0xDFFF)) { + var a = c & 0x3FF; + var b = d & 0x3FF; + i += 1; + cps.push(0x10000 + (a << 10) + b); + } else { + cps.push(0xFFFD); + } + } + } + i += 1; + } + return cps; + } +} \ No newline at end of file diff --git a/src/nid/utils/CompressionAlgorithm.ts b/src/nid/utils/CompressionAlgorithm.ts new file mode 100644 index 0000000..e77712d --- /dev/null +++ b/src/nid/utils/CompressionAlgorithm.ts @@ -0,0 +1,12 @@ +/** + * JavaScript DataArray + * version : 0.2 + * @author Nidin Vinayakan | nidinthb@gmail.com + */ +export class CompressionAlgorithm { + + static DEFLATE:string = "deflate"; + static LZMA:string = "lzma"; + static ZLIB:string = "zlib"; + +} \ No newline at end of file diff --git a/src/nid/utils/DataArray.ts b/src/nid/utils/DataArray.ts new file mode 100644 index 0000000..abcd7c0 --- /dev/null +++ b/src/nid/utils/DataArray.ts @@ -0,0 +1,133 @@ +import {ByteArray} from "./ByteArray"; +import {CompressionAlgorithm} from "./CompressionAlgorithm"; +import {LZMAHelper} from "./LZMAHelper"; +/** + * JavaScript DataArray + * version : 0.2 + * @author Nidin Vinayakan | nidinthb@gmail.com + * + * Extended ActionScript3 ByteArray API implementation in JavaScript + * limitation : size of DataArray cannot be changed + */ + +export class DataArray extends ByteArray { + static BIG_ENDIAN:string = "bigEndian"; + static LITTLE_ENDIAN:string = "littleEndian"; + + constructor(buffer?:ArrayBuffer, offset:number = 0, length:number = 0) { + + super(buffer, offset, length); + } + + public compress(algorithm:string = CompressionAlgorithm.LZMA):void { + throw "Compression error! " + algorithm + " not implemented"; + if (algorithm == CompressionAlgorithm.LZMA) { + + } else { + throw "Compression error! " + algorithm + " not implemented"; + } + } + + public decompressBuffer(algorithm:string = CompressionAlgorithm.LZMA):void { + if (algorithm == CompressionAlgorithm.LZMA) { + try { + this.buffer = LZMAHelper.decodeBuffer(this.buffer); + } catch (e) { + throw "Uncompression error! " + algorithm + " not implemented"; + } + } else if (algorithm == CompressionAlgorithm.ZLIB) { + /*this.buffer = ZLIBHelper.decodeBuffer(this.buffer);*/ + } else { + throw "Uncompression error! " + algorithm + " not implemented"; + } + } + + public decompress(algorithm:string = CompressionAlgorithm.LZMA):void { + if (algorithm == CompressionAlgorithm.LZMA) { + try { + this.array = LZMAHelper.decode(this.array); + } catch (e) { + throw "Uncompression error! " + algorithm + " not implemented"; + } + } else if (algorithm == CompressionAlgorithm.ZLIB) { + /*this.array = ZLIBHelper.decode(this.array);*/ + } else { + throw "Uncompression error! " + algorithm + " not implemented"; + } + } + + public compressAsync(algorithm:string, callback):void { + throw "Compression error! " + algorithm + " not implemented"; + if (algorithm == CompressionAlgorithm.LZMA) { + + } else { + throw "Compression error! " + algorithm + " not implemented"; + } + } + + public decompressAsync(algorithm:string = CompressionAlgorithm.LZMA, callback = null):void { + if (algorithm == CompressionAlgorithm.LZMA) { + LZMAHelper.decodeAsync(this.buffer, function (_data) { + this.buffer = _data; + }) + } else { + throw "Uncompression error! " + algorithm + " not implemented"; + } + } + + public deflate():void { + } + + public inflate():void { + } + + /** + * Reads the number of data bytes, specified by the length parameter, from the byte stream. + * The bytes are read into the DataArray object specified by the bytes parameter, + * and the bytes are written into the destination ByteArray starting at the _position specified by offset. + * @param bytes The DataArray object to read data into. + * @param offset The offset (_position) in bytes at which the read data should be written. + * @param length The number of bytes to read. The default value of 0 causes all available data to be read. + */ + + public readBytesAsByteArray(_bytes:DataArray = null, offset:number = 0, length:number = 0, createNewBuffer:boolean = false):DataArray { + if (length == 0) { + length = this.bytesAvailable; + } + else if (!this.validate(length)) return null; + + if (createNewBuffer) { + _bytes = _bytes == null ? new DataArray(new ArrayBuffer(length)) : _bytes; + //This method is expensive + for (var i = 0; i < length; i++) { + _bytes.data.setUint8(i + offset, this.data.getUint8(this.position++)); + } + } else { + //Offset argument ignored + _bytes = _bytes == null ? new DataArray(null) : _bytes; + _bytes.dataView = new DataView(this.data.buffer, this.bufferOffset + this.position, length); + this.position += length; + } + + return _bytes; + } + + /** + * Reads an object from the byte array, encoded in AMF + * serialized format. + * @return The deserialized object. + */ + public readObject():any { + //return this.readAmfObject(); + return null; + } + + /** + * Writes an object into the byte array in AMF + * serialized format. + * @param object The object to serialize. + */ + public writeObject(value:any):void { + + } +} \ No newline at end of file diff --git a/src/nid/utils/HalfPrecisionWriter.ts b/src/nid/utils/HalfPrecisionWriter.ts new file mode 100644 index 0000000..bc0df02 --- /dev/null +++ b/src/nid/utils/HalfPrecisionWriter.ts @@ -0,0 +1,118 @@ +import {BitArray} from "./BitArray"; +/****************************************************************************** + * This file contains code licensed for use under the BSD license, and was + * modified from the original C source by James Tursa as provided at the + * MatLab Central site here: + * + * http://www.mathworks.com/matlabcentral/fileexchange/23173 + * + * It has been modified to compile under ActionScript 3 for handling the + * FLOAT16 data format used in Adobe's SWF file format, which is the same + * as the IEEE 754r Half Precision format implemented by Mr. Tursa in the + * original source. + * + * The original license follows: + * + * Copyright (c) 2009, James Tursa + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the distribution + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +export class HalfPrecisionWriter { + + static write(value:number, data:BitArray) { + + data.resetBitsPending(); + + var dword:number; + var sign:number; + var exponent:number; + var significand:number; + var halfSignificand:number; + var signedExponent:number; + var result:number; + var p:number; + + p = data.position; + data.writeDouble(value); + data.position -= 4; + dword = data.readUnsignedInt(); + data.position = p; + + if ((dword & 0x7FFFFFFF) == 0) { // Signed zero + result = dword >> 16; + } + else { + + sign = dword & 0x80000000; + exponent = dword & 0x7FF00000; + significand = dword & 0x000FFFFF; + + if (exponent == 0) { // Denormal will underflow, signed zero + result = sign >> 16; + } + else if (exponent == 0x7FF00000) { // Infinity or NaN (all exponent bits set) + if (significand == 0) { + result = ((sign >> 16) | 0x7C00); // Signed infinity + } + else { + result = 0xFE00; // NaN, only 1st mantissa bit is set + } + } + else { // Normalized number + sign = sign >> 16; + signedExponent = (exponent >> 20) - 1023 + 15; // Reset the bias to half-precision + if (signedExponent >= 0x1F) { // Overflow + result = ((significand >> 16) | 0x7C00); // Signed infinity + } + else if (signedExponent <= 0) { // Underflow + if ((10 - signedExponent) > 21) { // Significand shifted off and no rounding possible + halfSignificand = 0; + } + else { + significand |= 0x00100000; // Add leading bit + halfSignificand = (significand >> (11 - signedExponent)); + if ((significand >> (10 - signedExponent)) & 0x00000001) { // Check for rounding + halfSignificand += 1; // Round, might overflow into exponent (okay) + } + } + result = (sign | halfSignificand); + } + else { + exponent = signedExponent << 10; + halfSignificand = significand >> 10; + if (significand & 0x00000200) { // Check for rounding + result = (sign | exponent | halfSignificand) + 1; // Round, may overflow to infinity (okay) + } + else { + result = (sign | exponent | halfSignificand); + } + } + } + } + + data.writeShort(result); + data.length = p + 2; + } +} \ No newline at end of file diff --git a/src/nid/utils/LZMAHelper.ts b/src/nid/utils/LZMAHelper.ts new file mode 100644 index 0000000..46290d7 --- /dev/null +++ b/src/nid/utils/LZMAHelper.ts @@ -0,0 +1,75 @@ +import {LZMA} from "../lzma/LZMA"; +/** + * @author Nidin Vinayakan | nidinthb@gmail.com + */ +export class LZMAHelper { + static decoder:LZMA = new LZMA(); + static decoderAsync:Worker; + static enableAsync:boolean = false; + static callback:Function; + static ENCODE:number = 1; + static DECODE:number = 2; + + static init():void { + var command = 0; + if (LZMAHelper.enableAsync) { + LZMAHelper.decoderAsync = new Worker('LZMAWorker.min.js'); + LZMAHelper.decoderAsync.onmessage = function (e) { + if (command == 0) { + command = e.data; + } else if (command == LZMAHelper.ENCODE) { + command = 0;//encode not implemented + } else if (command == LZMAHelper.DECODE) { + command = 0; + LZMAHelper.callback(e.data); + LZMAHelper.callback = null; + } + } + } + } + + /** + * TODO : Implement encoder + * @param data + * @returns {null} + */ + static encode(data:ArrayBuffer):ArrayBuffer { + return null; + } + + static decodeBuffer(data:ArrayBuffer):ArrayBuffer { + return LZMAHelper.decoder.decode(new Uint8Array(data)).buffer; + } + + static decode(data:Uint8Array):Uint8Array { + return LZMAHelper.decoder.decode(data); + } + + /** + * TODO : Implement encoder + * @param data + * @param _callback + */ + static encodeAsync(data:ArrayBuffer, _callback:Function):void { + if (LZMAHelper.enableAsync) { + + } else { + console.log('Error! Asynchronous encoding is disabled'); + } + } + + static decodeAsync(data:ArrayBuffer, _callback:Function):void { + if (LZMAHelper.enableAsync) { + if (LZMAHelper.callback == null) { + LZMAHelper.callback = _callback; + LZMAHelper.decoderAsync.postMessage(LZMAHelper.DECODE); + LZMAHelper.decoderAsync.postMessage(data, [data]); + } else { + console.log('Warning! Another LZMA decoding is running...'); + } + } else { + console.log('Error! Asynchronous decoding is disabled'); + } + } +} +LZMAHelper.init(); \ No newline at end of file diff --git a/src/nid/utils/MEMORY.ts b/src/nid/utils/MEMORY.ts new file mode 100644 index 0000000..89db172 --- /dev/null +++ b/src/nid/utils/MEMORY.ts @@ -0,0 +1,46 @@ +"use strict"; +"use asm"; +/** + * @author Nidin Vinayakan | nidinthb@gmail.com + */ +export class MEMORY { + static u8Index:number = 0; + static u16Index:number = 0; + static u32Index:number = 0; + static u8:Uint32Array; + static u16:Uint32Array; + static u32:Uint32Array; + + static allocateUint8(len:number):void { + MEMORY.u8 = new Uint8Array(len); + } + + static allocateUint16(len:number):void { + MEMORY.u16 = new Uint16Array(len); + } + + static allocateUint32(len:number):void { + MEMORY.u32 = new Uint32Array(len); + } + + static getUint8():number { + if (!MEMORY.u8) { + MEMORY.allocateUint8(10); + } + return MEMORY.u8Index++; + } + + static getUint16():number { + if (!MEMORY.u16) { + MEMORY.allocateUint16(24); + } + return MEMORY.u16Index++; + } + + static getUint32():number { + if (!MEMORY.u32) { + MEMORY.allocateUint32(10); + } + return MEMORY.u32Index++; + } +} \ No newline at end of file diff --git a/src/nid/utils/StringUtils.ts b/src/nid/utils/StringUtils.ts new file mode 100644 index 0000000..3fbde40 --- /dev/null +++ b/src/nid/utils/StringUtils.ts @@ -0,0 +1,33 @@ +"use strict"; +/** + * String Utilities + * @author Nidin Vinayakan | nidinthb@gmail.com + */ +export class StringUtils { + + static encoder:any; + + static encodeString(str):Uint8Array { + if (!StringUtils.encoder) { + if (window["TextEncoder"]) { + StringUtils.encoder = new window["TextEncoder"](); + } else { + //fallback + StringUtils.encoder = { + encode: function (str:string):Uint8Array { + var tmp = str.split(''); + var data:Uint8Array = new Uint8Array(tmp.length); + var i:number; + var il:number; + + for (i = 0, il = tmp.length; i < il; i++) { + data[i] = (tmp[i].charCodeAt(0) & 0xff) >>> 0; + } + return data; + } + } + } + } + return StringUtils.encoder.encode(str); + } +} \ No newline at end of file diff --git a/src/nid/utils/ZLIBHelper.ts b/src/nid/utils/ZLIBHelper.ts new file mode 100644 index 0000000..4c02361 --- /dev/null +++ b/src/nid/utils/ZLIBHelper.ts @@ -0,0 +1,70 @@ +"use strict"; +import {ZLIB} from "../zlib/ZLIB"; +/** + * @author Nidin Vinayakan | nidinthb@gmail.com + */ +export class ZLIBHelper { + static decoder:ZLIB = new ZLIB(); + static decoderAsync:Worker = new Worker('ZLIBWorker.min.js'); + static callback:Function; + static ENCODE:number = 1; + static DECODE:number = 2; + + static init():void { + var command = 0; + ZLIBHelper.decoderAsync.onmessage = function (e) { + if (command == 0) { + command = e.data; + } else if (command == ZLIBHelper.ENCODE) { + command = 0;//encode not implemented + } else if (command == ZLIBHelper.DECODE) { + command = 0; + ZLIBHelper.callback(e.data); + ZLIBHelper.callback = null; + } + } + } + + /** + * TODO : Implement encoder + * @param data + * @returns {null} + */ + static encodeBuffer(data:ArrayBuffer):ArrayBuffer { + throw "ZLIB encoder not implemented!"; + return null; + } + + static encode(data:Uint8Array):Uint8Array { + throw "ZLIB encoder not implemented!"; + return null; + } + + static decodeBuffer(data:ArrayBuffer):ArrayBuffer { + return ZLIBHelper.decoder.decode(new Uint8Array(data)).buffer; + } + + static decode(data:Uint8Array):Uint8Array { + return ZLIBHelper.decoder.decode(data); + } + + /** + * TODO : Implement encoder + * @param data + * @param _callback + */ + static encodeBufferAsync(data:ArrayBuffer, _callback:Function):void { + + } + + static decodeBufferAsync(data:ArrayBuffer, _callback:Function):void { + if (ZLIBHelper.callback == null) { + ZLIBHelper.callback = _callback; + ZLIBHelper.decoderAsync.postMessage(ZLIBHelper.DECODE); + ZLIBHelper.decoderAsync.postMessage(data, [data]); + } else { + console.log('Warning! Another ZLIB decoding is running...'); + } + } +} +ZLIBHelper.init(); \ No newline at end of file diff --git a/src/nid/zlib/Adler32.ts b/src/nid/zlib/Adler32.ts new file mode 100644 index 0000000..add685a --- /dev/null +++ b/src/nid/zlib/Adler32.ts @@ -0,0 +1,66 @@ +"use strict"; +/** + * ZLIB Decoder + * @author Nidin Vinayakan | nidinthb@gmail.com + * + */ + +export class Adler32 { + + static OptimizationParameter:number = 1024; + static encoder:any; + + static calc(array) { + if (typeof(array) === 'string') { + array = Adler32.encodeString(array); + } + return Adler32.update(1, array); + } + + static update(adler, array) { + var s1:number = adler & 0xffff; + var s2:number = (adler >>> 16) & 0xffff; + var len:number = array.length; + var tlen:number;//loop length + var i:number = 0;//array index + + while (len > 0) { + tlen = len > Adler32.OptimizationParameter ? + Adler32.OptimizationParameter : len; + len -= tlen; + do { + s1 += array[i++]; + s2 += s1; + } while (--tlen); + + s1 %= 65521; + s2 %= 65521; + } + + return ((s2 << 16) | s1) >>> 0; + } + + static encodeString(str:string) { + if(!Adler32.encoder){ + if(window["TextEncoder"]){ + Adler32.encoder = new window["TextEncoder"](); + }else{ + //fallback + Adler32.encoder = { + encode: function (str:string):Uint8Array { + var tmp = str.split(''); + var data:Uint8Array = new Uint8Array(tmp.length); + var i:number; + var il:number; + + for (i = 0, il = tmp.length; i < il; i++) { + data[i] = (tmp[i].charCodeAt(0) & 0xff) >>> 0; + } + return data; + } + } + } + } + return Adler32.encoder.encode(str); + } +} \ No newline at end of file diff --git a/src/nid/zlib/CRC32.ts b/src/nid/zlib/CRC32.ts new file mode 100644 index 0000000..49b0795 --- /dev/null +++ b/src/nid/zlib/CRC32.ts @@ -0,0 +1,107 @@ +"use strict"; +/** + * ZLIB CRC32 + * @author Nidin Vinayakan | nidinthb@gmail.com + * + */ + +export class CRC32 { + + static ZLIB_CRC32_COMPACT:boolean = false; + + static single(num, crc) { + return (CRC32.Table[(num ^ crc) & 0xff] ^ (num >>> 8)) >>> 0; + } + + static calc(data, pos, length) { + return CRC32.update(data, 0, pos, length); + } + + static update(data, crc, pos, length) { + var table = CRC32.Table; + var i = (typeof pos === 'number') ? pos : (pos = 0); + var il = (typeof length === 'number') ? length : data.length; + + crc ^= 0xffffffff; + + // loop unrolling for performance + for (i = il & 7; i--; ++pos) { + crc = (crc >>> 8) ^ table[(crc ^ data[pos]) & 0xff]; + } + for (i = il >> 3; i--; pos += 8) { + crc = (crc >>> 8) ^ table[(crc ^ data[pos]) & 0xff]; + crc = (crc >>> 8) ^ table[(crc ^ data[pos + 1]) & 0xff]; + crc = (crc >>> 8) ^ table[(crc ^ data[pos + 2]) & 0xff]; + crc = (crc >>> 8) ^ table[(crc ^ data[pos + 3]) & 0xff]; + crc = (crc >>> 8) ^ table[(crc ^ data[pos + 4]) & 0xff]; + crc = (crc >>> 8) ^ table[(crc ^ data[pos + 5]) & 0xff]; + crc = (crc >>> 8) ^ table[(crc ^ data[pos + 6]) & 0xff]; + crc = (crc >>> 8) ^ table[(crc ^ data[pos + 7]) & 0xff]; + } + + return (crc ^ 0xffffffff) >>> 0; + } + + static Table = CRC32.ZLIB_CRC32_COMPACT ? (function () { + var table = new Uint32Array(256); + var c:number; + var i:number; + var j:number; + + for (i = 0; i < 256; ++i) { + c = i; + for (j = 0; j < 8; ++j) { + c = (c & 1) ? (0xedB88320 ^ (c >>> 1)) : (c >>> 1); + } + table[i] = c >>> 0; + } + + return table; + })() : new Uint32Array(CRC32.Table_); + + static Table_ = [ + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, + 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, + 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, + 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, + 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, + 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, + 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, + 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, + 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, + 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, + 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, + 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, + 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, + 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, + 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, + 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, + 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, + 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, + 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, + 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, + 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, + 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d + ]; +} \ No newline at end of file diff --git a/src/nid/zlib/CompressionMethod.ts b/src/nid/zlib/CompressionMethod.ts new file mode 100644 index 0000000..8468674 --- /dev/null +++ b/src/nid/zlib/CompressionMethod.ts @@ -0,0 +1,18 @@ +"use strict"; +/** + * CompressionMethod + * @author Nidin Vinayakan | nidinthb@gmail.com + * + */ + +export class CompressionMethod { + + static ZLIB = { + DEFLATE: 8, + RESERVED: 15 + }; + static ZIP = { + STORE: 0, + DEFLATE: 8 + }; +} \ No newline at end of file diff --git a/src/nid/zlib/Huffman.ts b/src/nid/zlib/Huffman.ts new file mode 100644 index 0000000..f87d1fd --- /dev/null +++ b/src/nid/zlib/Huffman.ts @@ -0,0 +1,65 @@ +"use strict"; +/** + * ZLIB Decoder + * @author Nidin Vinayakan | nidinthb@gmail.com + */ +export class Huffman { + + /** + * build huffman table from length list + * @param lengths:Uint8Array lengths length list + * @return huffman table. + */ + static buildHuffmanTable(lengths):any { + var listSize = lengths.length;//length list size + var maxCodeLength = 0;//max code length for table size + var minCodeLength = Number.POSITIVE_INFINITY;//min code length for table size + var size;//table size + var table;//huffman code table + var bitLength;//bit length + var code;//huffman code + var skip;//skip length for table filling + var reversed;//reversed code + var rtemp;//reverse temp + var i;//loop counter + var il;//loop limit + var j;//loop counter + var value;//table value + + for (i = 0, il = listSize; i < il; ++i) { + if (lengths[i] > maxCodeLength) { + maxCodeLength = lengths[i]; + } + if (lengths[i] < minCodeLength) { + minCodeLength = lengths[i]; + } + } + + size = 1 << maxCodeLength; + table = new Uint32Array(size); + + for (bitLength = 1, code = 0, skip = 2; bitLength <= maxCodeLength;) { + for (i = 0; i < listSize; ++i) { + if (lengths[i] === bitLength) { + for (reversed = 0, rtemp = code, j = 0; j < bitLength; ++j) { + reversed = (reversed << 1) | (rtemp & 1); + rtemp >>= 1; + } + + value = (bitLength << 16) | i; + for (j = reversed; j < size; j += skip) { + table[j] = value; + } + + ++code; + } + } + + ++bitLength; + code <<= 1; + skip <<= 1; + } + + return [table, maxCodeLength, minCodeLength]; + } +} \ No newline at end of file diff --git a/src/nid/zlib/Inflate.ts b/src/nid/zlib/Inflate.ts new file mode 100644 index 0000000..19c4ad9 --- /dev/null +++ b/src/nid/zlib/Inflate.ts @@ -0,0 +1,108 @@ +import {RawInflate} from "./RawInflate"; +import {CompressionMethod} from "./CompressionMethod"; +import {Adler32} from "./Adler32"; +"use strict"; +/** + * ZLIB Decoder + * @author Nidin Vinayakan | nidinthb@gmail.com + * + */ +export class Inflate { + /** @type {number} */ + public bufferSize; + /** @type {Inflate.BufferType} */ + public bufferType; + /** @type {number} */ + public cmf; + /** @type {number} */ + public flg; + + /** @type {!(Uint8Array|Array)} */ + private input; + private method; + /** @type {number} */ + private ip = 0; + /** @type {RawInflate} */ + private rawinflate; + /** @type {(boolean|undefined)} verify flag. */ + private verify; + + static BufferType = RawInflate.BufferType; + + constructor(input, opt_params = null) { + + this.input = input; + + // option parameters + if (opt_params || !(opt_params = {})) { + if (opt_params['index']) { + this.ip = opt_params['index']; + } + if (opt_params['verify']) { + this.verify = opt_params['verify']; + } + } + + // Compression Method and Flags + this.cmf = input[this.ip++]; + this.flg = input[this.ip++]; + + // compression method + switch (this.cmf & 0x0f) { + case CompressionMethod.ZLIB.DEFLATE: + this.method = CompressionMethod.ZLIB.DEFLATE; + break; + default: + throw new Error('unsupported compression method'); + } + + // fcheck + if (((this.cmf << 8) + this.flg) % 31 !== 0) { + throw new Error('invalid fcheck flag:' + ((this.cmf << 8) + this.flg) % 31); + } + + // fdict (not supported) + if (this.flg & 0x20) { + throw new Error('fdict flag is not supported'); + } + + // RawInflate + this.rawinflate = new RawInflate(input, { + 'index': this.ip, + 'bufferSize': opt_params['bufferSize'], + 'bufferType': opt_params['bufferType'], + 'resize': opt_params['resize'] + }); + + } + + /** + * decompress. + * @return {!(Uint8Array|Array)} inflated buffer. + */ + public decompress() { + /** @type {!(Array|Uint8Array)} input buffer. */ + var input = this.input; + /** @type {!(Uint8Array|Array)} inflated buffer. */ + var buffer; + /** @type {number} adler-32 checksum */ + var adler32; + + buffer = this.rawinflate.decompress(); + this.ip = this.rawinflate.ip; + + // verify adler-32 + if (this.verify) { + adler32 = ( + input[this.ip++] << 24 | input[this.ip++] << 16 | + input[this.ip++] << 8 | input[this.ip++] + ) >>> 0; + + if (adler32 !== Adler32.calc(buffer)) { + throw new Error('invalid adler-32 checksum'); + } + } + + return buffer; + } +} \ No newline at end of file diff --git a/src/nid/zlib/RawInflate.ts b/src/nid/zlib/RawInflate.ts new file mode 100644 index 0000000..34f4253 --- /dev/null +++ b/src/nid/zlib/RawInflate.ts @@ -0,0 +1,691 @@ +import {Huffman} from "./Huffman"; +"use strict"; +/** + * ZLIB Decoder + * @author Nidin Vinayakan | nidinthb@gmail.com + * + */ + +export class RawInflate { + + private ZLIB_RAW_INFLATE_BUFFER_SIZE:number = 0x8000; // [ 0x8000 >= ZLIB_BUFFER_BLOCK_SIZE ] + + /** @type {!(Array.|Uint8Array)} inflated buffer */ + public buffer:Uint8Array; + public blocks; + public bufferSize:number;//block size + public totalpos:number;//total output buffer pointer + public ip:number;//input buffer pointer + public bitsbuf:number;//bit stream reader buffer + public bitsbuflen:number;//bit stream reader buffer size + public input:Uint8Array;//input buffer + public output:Uint8Array;//output buffer + public op:number;//output buffer pointer + public bfinal:boolean;//is final block flag + public bufferType:any;//buffer management + public resize:boolean;//resize flag for memory size optimization + public prev;//previous RLE value + public currentLitlenTable; + + static BufferType = { + BLOCK: 0, + ADAPTIVE: 1 + }; + //max backward length for LZ77 + static MaxBackwardLength = 32768; + //max copy length for LZ77 + static MaxCopyLength = 32768; + //huffman order + static Order:Uint16Array = new Uint16Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]); + //huffman length code table. + static LengthCodeTable:Uint16Array = new Uint16Array([ + 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, + 0x000d, 0x000f, 0x0011, 0x0013, 0x0017, 0x001b, 0x001f, 0x0023, 0x002b, + 0x0033, 0x003b, 0x0043, 0x0053, 0x0063, 0x0073, 0x0083, 0x00a3, 0x00c3, + 0x00e3, 0x0102, 0x0102, 0x0102 + ]); + //huffman length extra-bits table. + static LengthExtraTable:Uint8Array = new Uint8Array([ + 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, + 5, 5, 0, 0, 0 + ]); + //huffman dist code table. + static DistCodeTable:Uint16Array = new Uint16Array([ + 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0007, 0x0009, 0x000d, 0x0011, + 0x0019, 0x0021, 0x0031, 0x0041, 0x0061, 0x0081, 0x00c1, 0x0101, 0x0181, + 0x0201, 0x0301, 0x0401, 0x0601, 0x0801, 0x0c01, 0x1001, 0x1801, 0x2001, + 0x3001, 0x4001, 0x6001 + ]); + //huffman dist extra-bits table. + static DistExtraTable:Uint8Array = new Uint8Array([ + 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, + 11, 12, 12, 13, 13 + ]); + //fixed huffman length code table + static FixedLiteralLengthTable:any; + //fixed huffman distance code table + static FixedDistanceTable:any; + + constructor(input:Uint8Array, opt_params) { + + if (!RawInflate.FixedLiteralLengthTable) { + var lengths = new Uint8Array(288); + var i, il; + + for (i = 0, il = lengths.length; i < il; ++i) { + lengths[i] = + (i <= 143) ? 8 : + (i <= 255) ? 9 : + (i <= 279) ? 7 : + 8; + } + RawInflate.FixedLiteralLengthTable = Huffman.buildHuffmanTable(lengths); + } + if (!RawInflate.FixedDistanceTable) { + var lengths = new Uint8Array(30); + var i, il; + + for (i = 0, il = lengths.length; i < il; ++i) { + lengths[i] = 5; + } + + RawInflate.FixedDistanceTable = Huffman.buildHuffmanTable(lengths); + } + + this.blocks = []; + this.bufferSize = this.ZLIB_RAW_INFLATE_BUFFER_SIZE; + this.totalpos = 0; + this.ip = 0; + this.bitsbuf = 0; + this.bitsbuflen = 0; + this.input = input; + this.output; + this.bfinal = false; + this.bufferType = RawInflate.BufferType.ADAPTIVE; + this.resize = false; + + // option parameters + if (opt_params || !(opt_params = {})) { + if (opt_params['index']) { + this.ip = opt_params['index']; + } + if (opt_params['bufferSize']) { + this.bufferSize = opt_params['bufferSize']; + } + if (opt_params['bufferType']) { + this.bufferType = opt_params['bufferType']; + } + if (opt_params['resize']) { + this.resize = opt_params['resize']; + } + } + + // initialize + switch (this.bufferType) { + case RawInflate.BufferType.BLOCK: + this.op = RawInflate.MaxBackwardLength; + this.output = + new Uint8Array( + RawInflate.MaxBackwardLength + + this.bufferSize + + RawInflate.MaxCopyLength + ); + break; + case RawInflate.BufferType.ADAPTIVE: + this.op = 0; + this.output = new Uint8Array(this.bufferSize); + this.expandBuffer = this.expandBufferAdaptive; + this.concatBuffer = this.concatBufferDynamic; + this.decodeHuffman = this.decodeHuffmanAdaptive; + break; + default: + throw new Error('invalid inflate mode'); + } + + } + + public decompress() { + while (!this.bfinal) { + this.parseBlock(); + } + + return this.concatBuffer(); + } + + private parseBlock() { + /** @type {number} header */ + var hdr = this.readBits(3); + + // BFINAL + if (hdr & 0x1) { + this.bfinal = true; + } + + // BTYPE + hdr >>>= 1; + switch (hdr) { + // uncompressed + case 0: + this.parseUncompressedBlock(); + break; + // fixed huffman + case 1: + this.parseFixedHuffmanBlock(); + break; + // dynamic huffman + case 2: + this.parseDynamicHuffmanBlock(); + break; + // reserved or other + default: + throw new Error('unknown BTYPE: ' + hdr); + } + } + + //read inflate bits + private readBits(length) { + var bitsbuf = this.bitsbuf; + var bitsbuflen = this.bitsbuflen; + var input = this.input; + var ip = this.ip; + + /** @type {number} */ + var inputLength = input.length; + /** @type {number} input and output byte. */ + var octet; + + // not enough buffer + while (bitsbuflen < length) { + // input byte + if (ip >= inputLength) { + throw new Error('input buffer is broken'); + } + + // concat octet + bitsbuf |= input[ip++] << bitsbuflen; + bitsbuflen += 8; + } + + // output byte + octet = bitsbuf & /* MASK */ ((1 << length) - 1); + bitsbuf >>>= length; + bitsbuflen -= length; + + this.bitsbuf = bitsbuf; + this.bitsbuflen = bitsbuflen; + this.ip = ip; + + return octet; + } + + //read huffman code using table + private readCodeByTable(table) { + var bitsbuf = this.bitsbuf; + var bitsbuflen = this.bitsbuflen; + var input = this.input; + var ip = this.ip; + + /** @type {number} */ + var inputLength = input.length; + /** @type {!(Array.|Uint8Array)} huffman code table */ + var codeTable = table[0]; + /** @type {number} */ + var maxCodeLength = table[1]; + /** @type {number} code length & code (16bit, 16bit) */ + var codeWithLength; + /** @type {number} code bits length */ + var codeLength; + + // not enough buffer + while (bitsbuflen < maxCodeLength) { + if (ip >= inputLength) { + break; + } + bitsbuf |= input[ip++] << bitsbuflen; + bitsbuflen += 8; + } + + // read max length + codeWithLength = codeTable[bitsbuf & ((1 << maxCodeLength) - 1)]; + codeLength = codeWithLength >>> 16; + + this.bitsbuf = bitsbuf >> codeLength; + this.bitsbuflen = bitsbuflen - codeLength; + this.ip = ip; + + return codeWithLength & 0xffff; + } + + private parseUncompressedBlock() { + var input = this.input; + var ip = this.ip; + var output = this.output; + var op = this.op; + + /** @type {number} */ + var inputLength = input.length; + /** @type {number} block length */ + var len; + /** @type {number} number for check block length */ + var nlen; + /** @type {number} output buffer length */ + var olength = output.length; + /** @type {number} copy counter */ + var preCopy; + + // skip buffered header bits + this.bitsbuf = 0; + this.bitsbuflen = 0; + + // len + if (ip + 1 >= inputLength) { + throw new Error('invalid uncompressed block header: LEN'); + } + len = input[ip++] | (input[ip++] << 8); + + // nlen + if (ip + 1 >= inputLength) { + throw new Error('invalid uncompressed block header: NLEN'); + } + nlen = input[ip++] | (input[ip++] << 8); + + // check len & nlen + if (len === ~nlen) { + throw new Error('invalid uncompressed block header: length verify'); + } + + // check size + if (ip + len > input.length) { + throw new Error('input buffer is broken'); + } + + // expand buffer + switch (this.bufferType) { + case RawInflate.BufferType.BLOCK: + // pre copy + while (op + len > output.length) { + preCopy = olength - op; + len -= preCopy; + output.set(input.subarray(ip, ip + preCopy), op); + op += preCopy; + ip += preCopy; + this.op = op; + output = this.expandBuffer(); + op = this.op; + } + break; + case RawInflate.BufferType.ADAPTIVE: + while (op + len > output.length) { + output = this.expandBuffer({fixRatio: 2}); + } + break; + default: + throw new Error('invalid inflate mode'); + } + + // copy + output.set(input.subarray(ip, ip + len), op); + op += len; + ip += len; + + this.ip = ip; + this.op = op; + this.output = output; + } + + private parseFixedHuffmanBlock() { + this.decodeHuffman( + RawInflate.FixedLiteralLengthTable, + RawInflate.FixedDistanceTable + ); + } + + private parseDynamicHuffmanBlock() { + /** @type {number} number of literal and length codes. */ + var hlit = this.readBits(5) + 257; + /** @type {number} number of distance codes. */ + var hdist = this.readBits(5) + 1; + /** @type {number} number of code lengths. */ + var hclen = this.readBits(4) + 4; + /** @type {!(Uint8Array|Array.)} code lengths. */ + var codeLengths = + new Uint8Array(RawInflate.Order.length); + /** @type {!Array} code lengths table. */ + var codeLengthsTable; + /** @type {!(Uint8Array|Array.)} literal and length code lengths. */ + var litlenLengths; + /** @type {!(Uint8Array|Array.)} distance code lengths. */ + var distLengths; + /** @type {number} loop counter. */ + var i; + + // decode code lengths + for (i = 0; i < hclen; ++i) { + codeLengths[RawInflate.Order[i]] = this.readBits(3); + } + codeLengthsTable = Huffman.buildHuffmanTable(codeLengths); + + /** + * decode function + * @param {number} num number of lengths. + * @param {!Array} table code lengths table. + * @param {!(Uint8Array|Array.)} lengths code lengths buffer. + * @return {!(Uint8Array|Array.)} code lengths buffer. + */ + + + // literal and length code + litlenLengths = new Uint8Array(hlit); + + // distance code + distLengths = new Uint8Array(hdist); + + this.prev = 0; + this.decodeHuffman( + Huffman.buildHuffmanTable(this.decode.call(this, hlit, codeLengthsTable, litlenLengths)), + Huffman.buildHuffmanTable(this.decode.call(this, hdist, codeLengthsTable, distLengths)) + ); + } + + private decode(num, table, lengths) { + var code:number; + var prev:number = this.prev; + var repeat:number; + var i:number; + + for (i = 0; i < num;) { + code = this.readCodeByTable(table); + switch (code) { + case 16: + repeat = 3 + this.readBits(2); + while (repeat--) { + lengths[i++] = prev; + } + break; + case 17: + repeat = 3 + this.readBits(3); + while (repeat--) { + lengths[i++] = 0; + } + prev = 0; + break; + case 18: + repeat = 11 + this.readBits(7); + while (repeat--) { + lengths[i++] = 0; + } + prev = 0; + break; + default: + lengths[i++] = code; + prev = code; + break; + } + } + + this.prev = prev; + + return lengths; + } + + private decodeHuffman(litlen, dist) { + var output = this.output; + var op = this.op; + + this.currentLitlenTable = litlen; + + /** @type {number} output position limit. */ + var olength = output.length - RawInflate.MaxCopyLength; + /** @type {number} huffman code. */ + var code; + /** @type {number} table index. */ + var ti; + /** @type {number} huffman code distination. */ + var codeDist; + /** @type {number} huffman code length. */ + var codeLength; + + while ((code = this.readCodeByTable(litlen)) !== 256) { + // literal + if (code < 256) { + if (op >= olength) { + this.op = op; + output = this.expandBuffer(); + op = this.op; + } + output[op++] = code; + + continue; + } + + // length code + ti = code - 257; + codeLength = RawInflate.LengthCodeTable[ti]; + if (RawInflate.LengthExtraTable[ti] > 0) { + codeLength += this.readBits(RawInflate.LengthExtraTable[ti]); + } + + // dist code + code = this.readCodeByTable(dist); + codeDist = RawInflate.DistCodeTable[code]; + if (RawInflate.DistExtraTable[code] > 0) { + codeDist += this.readBits(RawInflate.DistExtraTable[code]); + } + + // lz77 decode + if (op >= olength) { + this.op = op; + output = this.expandBuffer(); + op = this.op; + } + while (codeLength--) { + output[op] = output[(op++) - codeDist]; + } + } + + while (this.bitsbuflen >= 8) { + this.bitsbuflen -= 8; + this.ip--; + } + this.op = op; + } + + private decodeHuffmanAdaptive(litlen, dist) { + var output = this.output; + var op = this.op; + + this.currentLitlenTable = litlen; + + /** @type {number} output position limit. */ + var olength = output.length; + /** @type {number} huffman code. */ + var code; + /** @type {number} table index. */ + var ti; + /** @type {number} huffman code distination. */ + var codeDist; + /** @type {number} huffman code length. */ + var codeLength; + + while ((code = this.readCodeByTable(litlen)) !== 256) { + // literal + if (code < 256) { + if (op >= olength) { + output = this.expandBuffer(); + olength = output.length; + } + output[op++] = code; + + continue; + } + + // length code + ti = code - 257; + codeLength = RawInflate.LengthCodeTable[ti]; + if (RawInflate.LengthExtraTable[ti] > 0) { + codeLength += this.readBits(RawInflate.LengthExtraTable[ti]); + } + + // dist code + code = this.readCodeByTable(dist); + codeDist = RawInflate.DistCodeTable[code]; + if (RawInflate.DistExtraTable[code] > 0) { + codeDist += this.readBits(RawInflate.DistExtraTable[code]); + } + + // lz77 decode + if (op + codeLength > olength) { + output = this.expandBuffer(); + olength = output.length; + } + while (codeLength--) { + output[op] = output[(op++) - codeDist]; + } + } + + while (this.bitsbuflen >= 8) { + this.bitsbuflen -= 8; + this.ip--; + } + this.op = op; + } + + private expandBuffer(opt_param = null) { + /** @type {!(Array.|Uint8Array)} store buffer. */ + var buffer = + new Uint8Array( + this.op - RawInflate.MaxBackwardLength + ); + /** @type {number} backward base point */ + var backward = this.op - RawInflate.MaxBackwardLength; + /** @type {number} copy index. */ + var i; + /** @type {number} copy limit */ + var il; + + var output = this.output; + + // copy to output buffer + buffer.set(output.subarray(RawInflate.MaxBackwardLength, buffer.length)); + + this.blocks.push(buffer); + this.totalpos += buffer.length; + + // copy to backward buffer + output.set( + output.subarray(backward, backward + RawInflate.MaxBackwardLength) + ); + + this.op = RawInflate.MaxBackwardLength; + + return output; + } + + private expandBufferAdaptive(opt_param) { + /** @type {!(Array.|Uint8Array)} store buffer. */ + var buffer; + /** @type {number} expantion ratio. */ + var ratio = (this.input.length / this.ip + 1) | 0; + /** @type {number} maximum number of huffman code. */ + var maxHuffCode; + /** @type {number} new output buffer size. */ + var newSize; + /** @type {number} max inflate size. */ + var maxInflateSize; + + var input = this.input; + var output = this.output; + + if (opt_param) { + if (typeof opt_param.fixRatio === 'number') { + ratio = opt_param.fixRatio; + } + if (typeof opt_param.addRatio === 'number') { + ratio += opt_param.addRatio; + } + } + + // calculate new buffer size + if (ratio < 2) { + maxHuffCode = + (input.length - this.ip) / this.currentLitlenTable[2]; + maxInflateSize = (maxHuffCode / 2 * 258) | 0; + newSize = maxInflateSize < output.length ? + output.length + maxInflateSize : + output.length << 1; + } else { + newSize = output.length * ratio; + } + + // buffer expantion + buffer = new Uint8Array(newSize); + buffer.set(output); + + this.output = buffer; + + return this.output; + } + + private concatBuffer() { + /** @type {number} buffer pointer. */ + var pos = 0; + /** @type {number} buffer pointer. */ + var limit = this.totalpos + (this.op - RawInflate.MaxBackwardLength); + /** @type {!(Array.|Uint8Array)} output block array. */ + var output = this.output; + /** @type {!Array} blocks array. */ + var blocks = this.blocks; + /** @type {!(Array.|Uint8Array)} output block array. */ + var block; + /** @type {!(Array.|Uint8Array)} output buffer. */ + var buffer = new Uint8Array(limit); + /** @type {number} loop counter. */ + var i; + /** @type {number} loop limiter. */ + var il; + /** @type {number} loop counter. */ + var j; + /** @type {number} loop limiter. */ + var jl; + + // single buffer + if (blocks.length === 0) { + return this.output.subarray(RawInflate.MaxBackwardLength, this.op) + } + + // copy to buffer + for (i = 0, il = blocks.length; i < il; ++i) { + block = blocks[i]; + for (j = 0, jl = block.length; j < jl; ++j) { + buffer[pos++] = block[j]; + } + } + + // current buffer + for (i = RawInflate.MaxBackwardLength, il = this.op; i < il; ++i) { + buffer[pos++] = output[i]; + } + + this.blocks = []; + this.buffer = buffer; + + return this.buffer; + } + + private concatBufferDynamic() { + /** @type {Array.|Uint8Array} output buffer. */ + var buffer; + var op = this.op; + + if (this.resize) { + buffer = new Uint8Array(op); + buffer.set(this.output.subarray(0, op)); + } else { + buffer = this.output.subarray(0, op); + } + + this.buffer = buffer; + + return this.buffer; + } +} \ No newline at end of file diff --git a/src/nid/zlib/ZLIB.ts b/src/nid/zlib/ZLIB.ts new file mode 100644 index 0000000..4d4d6d4 --- /dev/null +++ b/src/nid/zlib/ZLIB.ts @@ -0,0 +1,23 @@ +import {Inflate} from "./Inflate"; +"use strict"; +/** + * ZLIB Decoder + * @author Nidin Vinayakan | nidinthb@gmail.com + * + */ + +export class ZLIB { + + constructor() { + + } + + public encode():any { + + } + + public decode(compressed):any { + var decompressed = new Inflate(compressed).decompress(); + } + +} \ No newline at end of file diff --git a/src/nid/zlib/ZLIBWorker.ts b/src/nid/zlib/ZLIBWorker.ts new file mode 100644 index 0000000..92acbf2 --- /dev/null +++ b/src/nid/zlib/ZLIBWorker.ts @@ -0,0 +1,30 @@ +import {ZLIB} from "./ZLIB"; +"use strict"; +export class ZLIBWorker { + static ENCODE:number = 1; + static DECODE:number = 2; + private decoder:ZLIB; + private command:number = 0; + + constructor() { + var _this = this; + this.decoder = new ZLIB(); + + addEventListener('message', (e:any) => { + if (_this.command == 0) { + _this.command = e.data; + } else if (_this.command == 1) { + _this.command = 0; + } else if (_this.command == 2) { + _this.decode(e.data); + } + }, false); + } + + private decode(data):void { + var result = this.decoder.decode(new Uint8Array(data)); + ( postMessage)(ZLIBWorker.DECODE); + ( postMessage)(result.buffer, [result.buffer]); + } +} +var zlib_w = new ZLIBWorker(); \ No newline at end of file diff --git a/src/utils/StringUtils.ts b/src/utils/StringUtils.ts deleted file mode 100644 index de51255..0000000 --- a/src/utils/StringUtils.ts +++ /dev/null @@ -1,19 +0,0 @@ -module nid.utils { - "use strict" - /** - * String Utilities - * @author Nidin Vinayakan | nidinthb@gmail.com - * - */ - export function stringToByteArray(str) { - var tmp = str.split(''); - var i:number; - var il:number; - - for (i = 0, il = tmp.length; i < il; i++) { - tmp[i] = (tmp[i].charCodeAt(0) & 0xff) >>> 0; - } - - return tmp; - } -} \ No newline at end of file diff --git a/src/zlib/Adler32.ts b/src/zlib/Adler32.ts deleted file mode 100644 index 9392994..0000000 --- a/src/zlib/Adler32.ts +++ /dev/null @@ -1,44 +0,0 @@ -/// -module nid.utils { - "use strict" - /** - * ZLIB Decoder - * @author Nidin Vinayakan | nidinthb@gmail.com - * - */ - import stringToByteArray = nid.utils.stringToByteArray; - - export class Adler32{ - - static OptimizationParameter:number = 1024; - - static calc(array){ - if (typeof(array) === 'string') { - array = stringToByteArray(array); - } - return Adler32.update(1, array); - } - static update(adler, array) { - var s1:number = adler & 0xffff; - var s2:number = (adler >>> 16) & 0xffff; - var len:number = array.length; - var tlen:number;//loop length - var i:number = 0;//array index - - while (len > 0) { - tlen = len > Adler32.OptimizationParameter ? - Adler32.OptimizationParameter : len; - len -= tlen; - do { - s1 += array[i++]; - s2 += s1; - } while (--tlen); - - s1 %= 65521; - s2 %= 65521; - } - - return ((s2 << 16) | s1) >>> 0; - } - } -} \ No newline at end of file diff --git a/src/zlib/CRC32.ts b/src/zlib/CRC32.ts deleted file mode 100644 index 25c0cbe..0000000 --- a/src/zlib/CRC32.ts +++ /dev/null @@ -1,106 +0,0 @@ -module nid.utils { - "use strict" - /** - * ZLIB CRC32 - * @author Nidin Vinayakan | nidinthb@gmail.com - * - */ - - export class CRC32{ - - static ZLIB_CRC32_COMPACT:boolean = false; - - static single(num, crc) { - return (CRC32.Table[(num ^ crc) & 0xff] ^ (num >>> 8)) >>> 0; - } - static calc(data, pos, length) { - return CRC32.update(data, 0, pos, length); - } - static update(data, crc, pos, length) { - var table = CRC32.Table; - var i = (typeof pos === 'number') ? pos : (pos = 0); - var il = (typeof length === 'number') ? length : data.length; - - crc ^= 0xffffffff; - - // loop unrolling for performance - for (i = il & 7; i--; ++pos) { - crc = (crc >>> 8) ^ table[(crc ^ data[pos]) & 0xff]; - } - for (i = il >> 3; i--; pos += 8) { - crc = (crc >>> 8) ^ table[(crc ^ data[pos ]) & 0xff]; - crc = (crc >>> 8) ^ table[(crc ^ data[pos + 1]) & 0xff]; - crc = (crc >>> 8) ^ table[(crc ^ data[pos + 2]) & 0xff]; - crc = (crc >>> 8) ^ table[(crc ^ data[pos + 3]) & 0xff]; - crc = (crc >>> 8) ^ table[(crc ^ data[pos + 4]) & 0xff]; - crc = (crc >>> 8) ^ table[(crc ^ data[pos + 5]) & 0xff]; - crc = (crc >>> 8) ^ table[(crc ^ data[pos + 6]) & 0xff]; - crc = (crc >>> 8) ^ table[(crc ^ data[pos + 7]) & 0xff]; - } - - return (crc ^ 0xffffffff) >>> 0; - } - static Table = CRC32.ZLIB_CRC32_COMPACT ? (function() { - var table = new Uint32Array(256); - var c:number; - var i:number; - var j:number; - - for (i = 0; i < 256; ++i) { - c = i; - for (j = 0; j < 8; ++j) { - c = (c & 1) ? (0xedB88320 ^ (c >>> 1)) : (c >>> 1); - } - table[i] = c >>> 0; - } - - return table; - })() : new Uint32Array(CRC32.Table_); - - static Table_ = [ - 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, - 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, - 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, - 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, - 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, - 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, - 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, - 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, - 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, - 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, - 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, - 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, - 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, - 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, - 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, - 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, - 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, - 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, - 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, - 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, - 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, - 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, - 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, - 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, - 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, - 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, - 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, - 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, - 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, - 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, - 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, - 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, - 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, - 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, - 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, - 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, - 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, - 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, - 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, - 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, - 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, - 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, - 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d - ]; - } -} \ No newline at end of file diff --git a/src/zlib/CompressionMethod.ts b/src/zlib/CompressionMethod.ts deleted file mode 100644 index 283e316..0000000 --- a/src/zlib/CompressionMethod.ts +++ /dev/null @@ -1,22 +0,0 @@ -module nid.utils { - "use strict" - /** - * CompressionMethod - * @author Nidin Vinayakan | nidinthb@gmail.com - * - */ - - export class CompressionMethod{ - - static ZLIB = { - DEFLATE: 8, - RESERVED: 15 - } - static ZIP = { - STORE: 0, - DEFLATE: 8 - } - - } - -} \ No newline at end of file diff --git a/src/zlib/Huffman.ts b/src/zlib/Huffman.ts deleted file mode 100644 index 25a715f..0000000 --- a/src/zlib/Huffman.ts +++ /dev/null @@ -1,70 +0,0 @@ -/// -module nid.utils { - "use strict" - /** - * ZLIB Decoder - * @author Nidin Vinayakan | nidinthb@gmail.com - */ - export class Huffman{ - - /** - * build huffman table from length list - * @param lengths:Uint8Array lengths length list - * @return huffman table. - */ - static buildHuffmanTable(lengths):any { - var listSize = lengths.length;//length list size - var maxCodeLength = 0;//max code length for table size - var minCodeLength = Number.POSITIVE_INFINITY;//min code length for table size - var size;//table size - var table;//huffman code table - var bitLength;//bit length - var code;//huffman code - var skip;//skip length for table filling - var reversed;//reversed code - var rtemp;//reverse temp - var i;//loop counter - var il;//loop limit - var j;//loop counter - var value;//table value - - for (i = 0, il = listSize; i < il; ++i) { - if (lengths[i] > maxCodeLength) { - maxCodeLength = lengths[i]; - } - if (lengths[i] < minCodeLength) { - minCodeLength = lengths[i]; - } - } - - size = 1 << maxCodeLength; - table = new Uint32Array(size); - - for (bitLength = 1, code = 0, skip = 2; bitLength <= maxCodeLength;) { - for (i = 0; i < listSize; ++i) { - if (lengths[i] === bitLength) { - for (reversed = 0, rtemp = code, j = 0; j < bitLength; ++j) { - reversed = (reversed << 1) | (rtemp & 1); - rtemp >>= 1; - } - - value = (bitLength << 16) | i; - for (j = reversed; j < size; j += skip) { - table[j] = value; - } - - ++code; - } - } - - ++bitLength; - code <<= 1; - skip <<= 1; - } - - return [table, maxCodeLength, minCodeLength]; - } - - } - -} \ No newline at end of file diff --git a/src/zlib/Inflate.ts b/src/zlib/Inflate.ts deleted file mode 100644 index 8c8d9d4..0000000 --- a/src/zlib/Inflate.ts +++ /dev/null @@ -1,108 +0,0 @@ -/// -module nid.utils { - "use strict" - /** - * ZLIB Decoder - * @author Nidin Vinayakan | nidinthb@gmail.com - * - */ - export class Inflate{ - /** @type {number} */ - public bufferSize; - /** @type {Inflate.BufferType} */ - public bufferType; - /** @type {number} */ - public cmf; - /** @type {number} */ - public flg; - - /** @type {!(Uint8Array|Array)} */ - private input; - private method; - /** @type {number} */ - private ip = 0; - /** @type {RawInflate} */ - private rawinflate; - /** @type {(boolean|undefined)} verify flag. */ - private verify; - - static BufferType = RawInflate.BufferType; - - constructor(input, opt_params=null) { - - this.input = input; - - // option parameters - if (opt_params || !(opt_params = {})) { - if (opt_params['index']) { - this.ip = opt_params['index']; - } - if (opt_params['verify']) { - this.verify = opt_params['verify']; - } - } - - // Compression Method and Flags - this.cmf = input[this.ip++]; - this.flg = input[this.ip++]; - - // compression method - switch (this.cmf & 0x0f) { - case CompressionMethod.ZLIB.DEFLATE: - this.method = CompressionMethod.ZLIB.DEFLATE; - break; - default: - throw new Error('unsupported compression method'); - } - - // fcheck - if (((this.cmf << 8) + this.flg) % 31 !== 0) { - throw new Error('invalid fcheck flag:' + ((this.cmf << 8) + this.flg) % 31); - } - - // fdict (not supported) - if (this.flg & 0x20) { - throw new Error('fdict flag is not supported'); - } - - // RawInflate - this.rawinflate = new RawInflate(input, { - 'index': this.ip, - 'bufferSize': opt_params['bufferSize'], - 'bufferType': opt_params['bufferType'], - 'resize': opt_params['resize'] - }); - - } - - /** - * decompress. - * @return {!(Uint8Array|Array)} inflated buffer. - */ - public decompress() { - /** @type {!(Array|Uint8Array)} input buffer. */ - var input = this.input; - /** @type {!(Uint8Array|Array)} inflated buffer. */ - var buffer; - /** @type {number} adler-32 checksum */ - var adler32; - - buffer = this.rawinflate.decompress(); - this.ip = this.rawinflate.ip; - - // verify adler-32 - if (this.verify) { - adler32 = ( - input[this.ip++] << 24 | input[this.ip++] << 16 | - input[this.ip++] << 8 | input[this.ip++] - ) >>> 0; - - if (adler32 !== Adler32.calc(buffer)) { - throw new Error('invalid adler-32 checksum'); - } - } - - return buffer; - } - } -} \ No newline at end of file diff --git a/src/zlib/RawInflate.ts b/src/zlib/RawInflate.ts deleted file mode 100644 index 00824ce..0000000 --- a/src/zlib/RawInflate.ts +++ /dev/null @@ -1,672 +0,0 @@ -/// -module nid.utils { - "use strict" - /** - * ZLIB Decoder - * @author Nidin Vinayakan | nidinthb@gmail.com - * - */ - import Huffman = nid.utils.Huffman; - - export class RawInflate{ - - private ZLIB_RAW_INFLATE_BUFFER_SIZE:number = 0x8000; // [ 0x8000 >= ZLIB_BUFFER_BLOCK_SIZE ] - - /** @type {!(Array.|Uint8Array)} inflated buffer */ - public buffer:Uint8Array; - public blocks; - public bufferSize:number;//block size - public totalpos:number;//total output buffer pointer - public ip:number;//input buffer pointer - public bitsbuf:number;//bit stream reader buffer - public bitsbuflen:number;//bit stream reader buffer size - public input:Uint8Array;//input buffer - public output:Uint8Array;//output buffer - public op:number;//output buffer pointer - public bfinal:boolean;//is final block flag - public bufferType:any;//buffer management - public resize:boolean;//resize flag for memory size optimization - public prev;//previous RLE value - public currentLitlenTable; - - static BufferType = { - BLOCK: 0, - ADAPTIVE: 1 - }; - //max backward length for LZ77 - static MaxBackwardLength = 32768; - //max copy length for LZ77 - static MaxCopyLength = 32768; - //huffman order - static Order:Uint16Array = new Uint16Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]); - //huffman length code table. - static LengthCodeTable:Uint16Array = new Uint16Array([ - 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, - 0x000d, 0x000f, 0x0011, 0x0013, 0x0017, 0x001b, 0x001f, 0x0023, 0x002b, - 0x0033, 0x003b, 0x0043, 0x0053, 0x0063, 0x0073, 0x0083, 0x00a3, 0x00c3, - 0x00e3, 0x0102, 0x0102, 0x0102 - ]); - //huffman length extra-bits table. - static LengthExtraTable:Uint8Array = new Uint8Array([ - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, - 5, 5, 0, 0, 0 - ]); - //huffman dist code table. - static DistCodeTable:Uint16Array = new Uint16Array([ - 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0007, 0x0009, 0x000d, 0x0011, - 0x0019, 0x0021, 0x0031, 0x0041, 0x0061, 0x0081, 0x00c1, 0x0101, 0x0181, - 0x0201, 0x0301, 0x0401, 0x0601, 0x0801, 0x0c01, 0x1001, 0x1801, 0x2001, - 0x3001, 0x4001, 0x6001 - ]); - //huffman dist extra-bits table. - static DistExtraTable:Uint8Array = new Uint8Array([ - 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, - 11, 12, 12, 13, 13 - ]); - //fixed huffman length code table - static FixedLiteralLengthTable:any; - //fixed huffman distance code table - static FixedDistanceTable:any; - - constructor(input:Uint8Array, opt_params) { - - if(!RawInflate.FixedLiteralLengthTable){ - var lengths = new Uint8Array(288); - var i, il; - - for (i = 0, il = lengths.length; i < il; ++i) { - lengths[i] = - (i <= 143) ? 8 : - (i <= 255) ? 9 : - (i <= 279) ? 7 : - 8; - } - RawInflate.FixedLiteralLengthTable = Huffman.buildHuffmanTable(lengths); - } - if(!RawInflate.FixedDistanceTable){ - var lengths = new Uint8Array(30); - var i, il; - - for (i = 0, il = lengths.length; i < il; ++i) { - lengths[i] = 5; - } - - RawInflate.FixedDistanceTable = Huffman.buildHuffmanTable(lengths); - } - - this.blocks = []; - this.bufferSize = this.ZLIB_RAW_INFLATE_BUFFER_SIZE; - this.totalpos = 0; - this.ip = 0; - this.bitsbuf = 0; - this.bitsbuflen = 0; - this.input = input; - this.output; - this.bfinal = false; - this.bufferType = RawInflate.BufferType.ADAPTIVE; - this.resize = false; - - // option parameters - if (opt_params || !(opt_params = {})) { - if (opt_params['index']) { - this.ip = opt_params['index']; - } - if (opt_params['bufferSize']) { - this.bufferSize = opt_params['bufferSize']; - } - if (opt_params['bufferType']) { - this.bufferType = opt_params['bufferType']; - } - if (opt_params['resize']) { - this.resize = opt_params['resize']; - } - } - - // initialize - switch (this.bufferType) { - case RawInflate.BufferType.BLOCK: - this.op = RawInflate.MaxBackwardLength; - this.output = - new Uint8Array( - RawInflate.MaxBackwardLength + - this.bufferSize + - RawInflate.MaxCopyLength - ); - break; - case RawInflate.BufferType.ADAPTIVE: - this.op = 0; - this.output = new Uint8Array(this.bufferSize); - this.expandBuffer = this.expandBufferAdaptive; - this.concatBuffer = this.concatBufferDynamic; - this.decodeHuffman = this.decodeHuffmanAdaptive; - break; - default: - throw new Error('invalid inflate mode'); - } - - } - public decompress() { - while (!this.bfinal) { - this.parseBlock(); - } - - return this.concatBuffer(); - } - private parseBlock() { - /** @type {number} header */ - var hdr = this.readBits(3); - - // BFINAL - if (hdr & 0x1) { - this.bfinal = true; - } - - // BTYPE - hdr >>>= 1; - switch (hdr) { - // uncompressed - case 0: - this.parseUncompressedBlock(); - break; - // fixed huffman - case 1: - this.parseFixedHuffmanBlock(); - break; - // dynamic huffman - case 2: - this.parseDynamicHuffmanBlock(); - break; - // reserved or other - default: - throw new Error('unknown BTYPE: ' + hdr); - } - } - //read inflate bits - private readBits(length) { - var bitsbuf = this.bitsbuf; - var bitsbuflen = this.bitsbuflen; - var input = this.input; - var ip = this.ip; - - /** @type {number} */ - var inputLength = input.length; - /** @type {number} input and output byte. */ - var octet; - - // not enough buffer - while (bitsbuflen < length) { - // input byte - if (ip >= inputLength) { - throw new Error('input buffer is broken'); - } - - // concat octet - bitsbuf |= input[ip++] << bitsbuflen; - bitsbuflen += 8; - } - - // output byte - octet = bitsbuf & /* MASK */ ((1 << length) - 1); - bitsbuf >>>= length; - bitsbuflen -= length; - - this.bitsbuf = bitsbuf; - this.bitsbuflen = bitsbuflen; - this.ip = ip; - - return octet; - } - //read huffman code using table - private readCodeByTable(table) { - var bitsbuf = this.bitsbuf; - var bitsbuflen = this.bitsbuflen; - var input = this.input; - var ip = this.ip; - - /** @type {number} */ - var inputLength = input.length; - /** @type {!(Array.|Uint8Array)} huffman code table */ - var codeTable = table[0]; - /** @type {number} */ - var maxCodeLength = table[1]; - /** @type {number} code length & code (16bit, 16bit) */ - var codeWithLength; - /** @type {number} code bits length */ - var codeLength; - - // not enough buffer - while (bitsbuflen < maxCodeLength) { - if (ip >= inputLength) { - break; - } - bitsbuf |= input[ip++] << bitsbuflen; - bitsbuflen += 8; - } - - // read max length - codeWithLength = codeTable[bitsbuf & ((1 << maxCodeLength) - 1)]; - codeLength = codeWithLength >>> 16; - - this.bitsbuf = bitsbuf >> codeLength; - this.bitsbuflen = bitsbuflen - codeLength; - this.ip = ip; - - return codeWithLength & 0xffff; - } - private parseUncompressedBlock() { - var input = this.input; - var ip = this.ip; - var output = this.output; - var op = this.op; - - /** @type {number} */ - var inputLength = input.length; - /** @type {number} block length */ - var len; - /** @type {number} number for check block length */ - var nlen; - /** @type {number} output buffer length */ - var olength = output.length; - /** @type {number} copy counter */ - var preCopy; - - // skip buffered header bits - this.bitsbuf = 0; - this.bitsbuflen = 0; - - // len - if (ip + 1 >= inputLength) { - throw new Error('invalid uncompressed block header: LEN'); - } - len = input[ip++] | (input[ip++] << 8); - - // nlen - if (ip + 1 >= inputLength) { - throw new Error('invalid uncompressed block header: NLEN'); - } - nlen = input[ip++] | (input[ip++] << 8); - - // check len & nlen - if (len === ~nlen) { - throw new Error('invalid uncompressed block header: length verify'); - } - - // check size - if (ip + len > input.length) { throw new Error('input buffer is broken'); } - - // expand buffer - switch (this.bufferType) { - case RawInflate.BufferType.BLOCK: - // pre copy - while (op + len > output.length) { - preCopy = olength - op; - len -= preCopy; - output.set(input.subarray(ip, ip + preCopy), op); - op += preCopy; - ip += preCopy; - this.op = op; - output = this.expandBuffer(); - op = this.op; - } - break; - case RawInflate.BufferType.ADAPTIVE: - while (op + len > output.length) { - output = this.expandBuffer({fixRatio: 2}); - } - break; - default: - throw new Error('invalid inflate mode'); - } - - // copy - output.set(input.subarray(ip, ip + len), op); - op += len; - ip += len; - - this.ip = ip; - this.op = op; - this.output = output; - } - private parseFixedHuffmanBlock() { - this.decodeHuffman( - RawInflate.FixedLiteralLengthTable, - RawInflate.FixedDistanceTable - ); - } - private parseDynamicHuffmanBlock() { - /** @type {number} number of literal and length codes. */ - var hlit = this.readBits(5) + 257; - /** @type {number} number of distance codes. */ - var hdist = this.readBits(5) + 1; - /** @type {number} number of code lengths. */ - var hclen = this.readBits(4) + 4; - /** @type {!(Uint8Array|Array.)} code lengths. */ - var codeLengths = - new Uint8Array(RawInflate.Order.length); - /** @type {!Array} code lengths table. */ - var codeLengthsTable; - /** @type {!(Uint8Array|Array.)} literal and length code lengths. */ - var litlenLengths; - /** @type {!(Uint8Array|Array.)} distance code lengths. */ - var distLengths; - /** @type {number} loop counter. */ - var i; - - // decode code lengths - for (i = 0; i < hclen; ++i) { - codeLengths[RawInflate.Order[i]] = this.readBits(3); - } - codeLengthsTable = Huffman.buildHuffmanTable(codeLengths); - - /** - * decode function - * @param {number} num number of lengths. - * @param {!Array} table code lengths table. - * @param {!(Uint8Array|Array.)} lengths code lengths buffer. - * @return {!(Uint8Array|Array.)} code lengths buffer. - */ - - - // literal and length code - litlenLengths = new Uint8Array(hlit); - - // distance code - distLengths = new Uint8Array(hdist); - - this.prev = 0; - this.decodeHuffman( - Huffman.buildHuffmanTable(this.decode.call(this, hlit, codeLengthsTable, litlenLengths)), - Huffman.buildHuffmanTable(this.decode.call(this, hdist, codeLengthsTable, distLengths)) - ); - } - private decode(num, table, lengths) { - var code:number; - var prev:number = this.prev; - var repeat:number; - var i:number; - - for (i = 0; i < num;) { - code = this.readCodeByTable(table); - switch (code) { - case 16: - repeat = 3 + this.readBits(2); - while (repeat--) { lengths[i++] = prev; } - break; - case 17: - repeat = 3 + this.readBits(3); - while (repeat--) { lengths[i++] = 0; } - prev = 0; - break; - case 18: - repeat = 11 + this.readBits(7); - while (repeat--) { lengths[i++] = 0; } - prev = 0; - break; - default: - lengths[i++] = code; - prev = code; - break; - } - } - - this.prev = prev; - - return lengths; - } - private decodeHuffman(litlen, dist) { - var output = this.output; - var op = this.op; - - this.currentLitlenTable = litlen; - - /** @type {number} output position limit. */ - var olength = output.length - RawInflate.MaxCopyLength; - /** @type {number} huffman code. */ - var code; - /** @type {number} table index. */ - var ti; - /** @type {number} huffman code distination. */ - var codeDist; - /** @type {number} huffman code length. */ - var codeLength; - - while ((code = this.readCodeByTable(litlen)) !== 256) { - // literal - if (code < 256) { - if (op >= olength) { - this.op = op; - output = this.expandBuffer(); - op = this.op; - } - output[op++] = code; - - continue; - } - - // length code - ti = code - 257; - codeLength = RawInflate.LengthCodeTable[ti]; - if (RawInflate.LengthExtraTable[ti] > 0) { - codeLength += this.readBits(RawInflate.LengthExtraTable[ti]); - } - - // dist code - code = this.readCodeByTable(dist); - codeDist = RawInflate.DistCodeTable[code]; - if (RawInflate.DistExtraTable[code] > 0) { - codeDist += this.readBits(RawInflate.DistExtraTable[code]); - } - - // lz77 decode - if (op >= olength) { - this.op = op; - output = this.expandBuffer(); - op = this.op; - } - while (codeLength--) { - output[op] = output[(op++) - codeDist]; - } - } - - while (this.bitsbuflen >= 8) { - this.bitsbuflen -= 8; - this.ip--; - } - this.op = op; - } - private decodeHuffmanAdaptive(litlen, dist) { - var output = this.output; - var op = this.op; - - this.currentLitlenTable = litlen; - - /** @type {number} output position limit. */ - var olength = output.length; - /** @type {number} huffman code. */ - var code; - /** @type {number} table index. */ - var ti; - /** @type {number} huffman code distination. */ - var codeDist; - /** @type {number} huffman code length. */ - var codeLength; - - while ((code = this.readCodeByTable(litlen)) !== 256) { - // literal - if (code < 256) { - if (op >= olength) { - output = this.expandBuffer(); - olength = output.length; - } - output[op++] = code; - - continue; - } - - // length code - ti = code - 257; - codeLength = RawInflate.LengthCodeTable[ti]; - if (RawInflate.LengthExtraTable[ti] > 0) { - codeLength += this.readBits(RawInflate.LengthExtraTable[ti]); - } - - // dist code - code = this.readCodeByTable(dist); - codeDist = RawInflate.DistCodeTable[code]; - if (RawInflate.DistExtraTable[code] > 0) { - codeDist += this.readBits(RawInflate.DistExtraTable[code]); - } - - // lz77 decode - if (op + codeLength > olength) { - output = this.expandBuffer(); - olength = output.length; - } - while (codeLength--) { - output[op] = output[(op++) - codeDist]; - } - } - - while (this.bitsbuflen >= 8) { - this.bitsbuflen -= 8; - this.ip--; - } - this.op = op; - } - private expandBuffer(opt_param=null) { - /** @type {!(Array.|Uint8Array)} store buffer. */ - var buffer = - new Uint8Array( - this.op - RawInflate.MaxBackwardLength - ); - /** @type {number} backward base point */ - var backward = this.op - RawInflate.MaxBackwardLength; - /** @type {number} copy index. */ - var i; - /** @type {number} copy limit */ - var il; - - var output = this.output; - - // copy to output buffer - buffer.set(output.subarray(RawInflate.MaxBackwardLength, buffer.length)); - - this.blocks.push(buffer); - this.totalpos += buffer.length; - - // copy to backward buffer - output.set( - output.subarray(backward, backward + RawInflate.MaxBackwardLength) - ); - - this.op = RawInflate.MaxBackwardLength; - - return output; - } - private expandBufferAdaptive(opt_param) { - /** @type {!(Array.|Uint8Array)} store buffer. */ - var buffer; - /** @type {number} expantion ratio. */ - var ratio = (this.input.length / this.ip + 1) | 0; - /** @type {number} maximum number of huffman code. */ - var maxHuffCode; - /** @type {number} new output buffer size. */ - var newSize; - /** @type {number} max inflate size. */ - var maxInflateSize; - - var input = this.input; - var output = this.output; - - if (opt_param) { - if (typeof opt_param.fixRatio === 'number') { - ratio = opt_param.fixRatio; - } - if (typeof opt_param.addRatio === 'number') { - ratio += opt_param.addRatio; - } - } - - // calculate new buffer size - if (ratio < 2) { - maxHuffCode = - (input.length - this.ip) / this.currentLitlenTable[2]; - maxInflateSize = (maxHuffCode / 2 * 258) | 0; - newSize = maxInflateSize < output.length ? - output.length + maxInflateSize : - output.length << 1; - } else { - newSize = output.length * ratio; - } - - // buffer expantion - buffer = new Uint8Array(newSize); - buffer.set(output); - - this.output = buffer; - - return this.output; - } - private concatBuffer() { - /** @type {number} buffer pointer. */ - var pos = 0; - /** @type {number} buffer pointer. */ - var limit = this.totalpos + (this.op - RawInflate.MaxBackwardLength); - /** @type {!(Array.|Uint8Array)} output block array. */ - var output = this.output; - /** @type {!Array} blocks array. */ - var blocks = this.blocks; - /** @type {!(Array.|Uint8Array)} output block array. */ - var block; - /** @type {!(Array.|Uint8Array)} output buffer. */ - var buffer = new Uint8Array(limit); - /** @type {number} loop counter. */ - var i; - /** @type {number} loop limiter. */ - var il; - /** @type {number} loop counter. */ - var j; - /** @type {number} loop limiter. */ - var jl; - - // single buffer - if (blocks.length === 0) { - return this.output.subarray(RawInflate.MaxBackwardLength, this.op) - } - - // copy to buffer - for (i = 0, il = blocks.length; i < il; ++i) { - block = blocks[i]; - for (j = 0, jl = block.length; j < jl; ++j) { - buffer[pos++] = block[j]; - } - } - - // current buffer - for (i = RawInflate.MaxBackwardLength, il = this.op; i < il; ++i) { - buffer[pos++] = output[i]; - } - - this.blocks = []; - this.buffer = buffer; - - return this.buffer; - } - private concatBufferDynamic() { - /** @type {Array.|Uint8Array} output buffer. */ - var buffer; - var op = this.op; - - if (this.resize) { - buffer = new Uint8Array(op); - buffer.set(this.output.subarray(0, op)); - } else { - buffer = this.output.subarray(0, op); - } - - this.buffer = buffer; - - return this.buffer; - } - } -} \ No newline at end of file diff --git a/src/zlib/ZLIB.lib.d.ts b/src/zlib/ZLIB.lib.d.ts deleted file mode 100644 index 530c66f..0000000 --- a/src/zlib/ZLIB.lib.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -/// -/// -/// -/// -/// -/// -/// -/// \ No newline at end of file diff --git a/src/zlib/ZLIB.ts b/src/zlib/ZLIB.ts deleted file mode 100644 index 3220ecc..0000000 --- a/src/zlib/ZLIB.ts +++ /dev/null @@ -1,24 +0,0 @@ -/// -module nid.utils { - "use strict" - /** - * ZLIB Decoder - * @author Nidin Vinayakan | nidinthb@gmail.com - * - */ - - export class ZLIB{ - - constructor(){ - - } - public encode():any{ - - } - public decode(compressed):any{ - var decompressed = new Inflate(compressed).decompress(); - } - - } - -} \ No newline at end of file diff --git a/src/zlib/ZLIBWorker.ts b/src/zlib/ZLIBWorker.ts deleted file mode 100644 index 6c00b7f..0000000 --- a/src/zlib/ZLIBWorker.ts +++ /dev/null @@ -1,34 +0,0 @@ -/// -module nid.utils{ - - "use strict" - export class ZLIBWorker - { - static ENCODE:number = 1; - static DECODE:number = 2; - private decoder:ZLIB; - private command:number = 0; - - constructor () - { - var _this = this; - this.decoder = new ZLIB(); - - addEventListener('message', (e:any) => { - if(_this.command == 0){ - _this.command = e.data; - }else if(_this.command == 1){ - _this.command = 0; - }else if(_this.command == 2){ - _this.decode(e.data); - } - }, false); - } - private decode(data):void{ - var result = this.decoder.decode(new Uint8Array(data)); - ( postMessage)(ZLIBWorker.DECODE); - ( postMessage)(result.buffer,[result.buffer]); - } - } -} -var zlib_w = new nid.utils.ZLIBWorker(); \ No newline at end of file diff --git a/test/ByteArrayTest.ts b/test/ByteArrayUnitTest.ts similarity index 89% rename from test/ByteArrayTest.ts rename to test/ByteArrayUnitTest.ts index 8d4996b..869bd9c 100644 --- a/test/ByteArrayTest.ts +++ b/test/ByteArrayUnitTest.ts @@ -1,8 +1,10 @@ -/// -/// -class ByteArrayTest extends tsUnit.TestClass { +import {ByteArray} from "../src/nid/utils/ByteArray"; +import {TestClass} from "./tsUnit"; +import {Test} from "./tsUnit"; + +class ByteArrayUnitTest extends TestClass { - private target = new nid.utils.ByteArray(new ArrayBuffer(1024 * 2)); + private target = new ByteArray(new ArrayBuffer(1024 * 2)); private BYTE_MAX = 127; private BYTE_MIN = -128; @@ -22,18 +24,18 @@ class ByteArrayTest extends tsUnit.TestClass { private DOUBLE_MIN = Number.MIN_VALUE; private UTF_STR = "this is a utf8 encoded string"; - private SIZE_OF_BOOLEAN = nid.utils.ByteArray.SIZE_OF_BOOLEAN; - private SIZE_OF_INT8 = nid.utils.ByteArray.SIZE_OF_INT8; - private SIZE_OF_INT16 = nid.utils.ByteArray.SIZE_OF_INT16; - private SIZE_OF_INT32 = nid.utils.ByteArray.SIZE_OF_INT32; - private SIZE_OF_UINT8 = nid.utils.ByteArray.SIZE_OF_UINT8; - private SIZE_OF_UINT16 = nid.utils.ByteArray.SIZE_OF_UINT16; - private SIZE_OF_UINT32 = nid.utils.ByteArray.SIZE_OF_UINT32; - private SIZE_OF_FLOAT32 = nid.utils.ByteArray.SIZE_OF_FLOAT32; - private SIZE_OF_FLOAT64 = nid.utils.ByteArray.SIZE_OF_FLOAT64; - + private SIZE_OF_BOOLEAN = ByteArray.SIZE_OF_BOOLEAN; + private SIZE_OF_INT8 = ByteArray.SIZE_OF_INT8; + private SIZE_OF_INT16 = ByteArray.SIZE_OF_INT16; + private SIZE_OF_INT32 = ByteArray.SIZE_OF_INT32; + private SIZE_OF_UINT8 = ByteArray.SIZE_OF_UINT8; + private SIZE_OF_UINT16 = ByteArray.SIZE_OF_UINT16; + private SIZE_OF_UINT32 = ByteArray.SIZE_OF_UINT32; + private SIZE_OF_FLOAT32 = ByteArray.SIZE_OF_FLOAT32; + private SIZE_OF_FLOAT64 = ByteArray.SIZE_OF_FLOAT64; + writeAndReadBoolean() { - //this.target.endian = nid.utils.ByteArray.LITTLE_ENDIAN; + //this.target.endian = ByteArray.LITTLE_ENDIAN; this.target.writeBoolean(true); this.target.position = this.target.position - this.SIZE_OF_BOOLEAN; var result = this.target.readBoolean(); @@ -226,14 +228,15 @@ class ByteArrayTest extends tsUnit.TestClass { } // new instance of tsUnit -var test = new tsUnit.Test(); +var test = new Test(); // add your test class (you can call this multiple times) -test.addTestClass(new ByteArrayTest()); +test.addTestClass(new ByteArrayUnitTest()); // Use the built in results display var TestRunner = { run:function run(){ test.showResults(document.getElementById('results'), test.run()); } -} \ No newline at end of file +}; +TestRunner.run(); \ No newline at end of file diff --git a/test/SimpleTest.ts b/test/SimpleTest.ts new file mode 100644 index 0000000..23eaf6e --- /dev/null +++ b/test/SimpleTest.ts @@ -0,0 +1,20 @@ +import {ByteArray} from "../src/nid/utils/ByteArray"; +/** + * Created by Nidin Vinayakan on 15-02-2016. + */ +export class SimpleTest{ + + constructor(){ + var byteArray = new ByteArray(); + byteArray.writeShort(52); + byteArray.writeInt(-56256); + byteArray.writeUnsignedInt(652); + byteArray.writeDouble(Math.random() * Number.MAX_VALUE); + byteArray.position = 0; + console.log(byteArray.readShort()); + console.log(byteArray.readInt()); + console.log(byteArray.readUnsignedInt()); + console.log(byteArray.readDouble()); + } +} +new SimpleTest(); \ No newline at end of file diff --git a/test/html/index-test.html b/test/html/index-test.html deleted file mode 100644 index 635a2dc..0000000 --- a/test/html/index-test.html +++ /dev/null @@ -1,21 +0,0 @@ - - - - - JavaScript ByteArray Test - - - - - -
- - diff --git a/test/html/index.html b/test/html/index.html deleted file mode 100644 index 84d6596..0000000 --- a/test/html/index.html +++ /dev/null @@ -1,26 +0,0 @@ - - - - - JavaScript ByteArray - - - - - - - - diff --git a/test/html/lzma.html b/test/lzma-test.html similarity index 100% rename from test/html/lzma.html rename to test/lzma-test.html diff --git a/test/simple-test.html b/test/simple-test.html new file mode 100644 index 0000000..0d4f769 --- /dev/null +++ b/test/simple-test.html @@ -0,0 +1,20 @@ + + + + + JavaScript DataArray + + + + + diff --git a/test/tsUnit.ts b/test/tsUnit.ts index 8627236..e40e8ce 100644 --- a/test/tsUnit.ts +++ b/test/tsUnit.ts @@ -1,245 +1,247 @@ -module tsUnit { - export interface ITestClass { +export interface ITestClass { - } +} - export class Test { - private tests: TestDefintion[] = []; - private testClass: TestClass = new TestClass(); +export class Test { + private tests:TestDefintion[] = []; + private testClass:TestClass = new TestClass(); - addTestClass(testClass: ITestClass, name: string = 'Tests'): void { - this.tests.push(new TestDefintion(testClass, name)); - } + addTestClass(testClass:ITestClass, name:string = 'Tests'):void { + this.tests.push(new TestDefintion(testClass, name)); + } - isReservedFunctionName(functionName: string): boolean { - for (var prop in this.testClass) { - if (prop === functionName) { - return true; - } + isReservedFunctionName(functionName:string):boolean { + for (var prop in this.testClass) { + if (prop === functionName) { + return true; } - return false; } + return false; + } - run() { - var testContext = new TestContext(); - var testResult = new TestResult(); - - for (var i = 0; i < this.tests.length; ++i) { - var testClass = this.tests[i].testClass; - var testName = this.tests[i].name; - for (var prop in testClass) { - if (!this.isReservedFunctionName(prop)) { - if (typeof testClass[prop] === 'function') { - if (typeof testClass['setUp'] === 'function') { - testClass['setUp'](); - } - try { - testClass[prop](testContext); - testResult.passes.push(new TestDescription(testName, prop, 'OK')); - } catch (err) { - testResult.errors.push(new TestDescription(testName, prop, err)); - } - if (typeof testClass['tearDown'] === 'function') { - testClass['tearDown'](); - } + run() { + var testContext = new TestContext(); + var testResult = new TestResult(); + + for (var i = 0; i < this.tests.length; ++i) { + var testClass = this.tests[i].testClass; + var testName = this.tests[i].name; + for (var prop in testClass) { + if (!this.isReservedFunctionName(prop)) { + if (typeof testClass[prop] === 'function') { + if (typeof testClass['setUp'] === 'function') { + testClass['setUp'](); + } + try { + testClass[prop](testContext); + testResult.passes.push(new TestDescription(testName, prop, 'OK')); + } catch (err) { + testResult.errors.push(new TestDescription(testName, prop, err)); + } + if (typeof testClass['tearDown'] === 'function') { + testClass['tearDown'](); } } } } - - return testResult; } - showResults(target: HTMLElement, result: TestResult) { - var template = '
' + - '

' + this.getTestResult(result) + '

' + - '

' + this.getTestSummary(result) + '

' + - '
' + - '

Errors

' + - '
    ' + this.getTestResultList(result.errors) + '
' + - '
' + - '
' + - '

Passing Tests

' + - '
    ' + this.getTestResultList(result.passes) + '
' + - '
' + - '
'; - - target.innerHTML = template; - } + return testResult; + } - private getTestResult(result: TestResult) { - return result.errors.length === 0 ? 'Test Passed' : 'Test Failed'; - } + showResults(target:HTMLElement, result:TestResult) { + var template = '
' + + '

' + this.getTestResult(result) + '

' + + '

' + this.getTestSummary(result) + '

' + + '
' + + '

Errors

' + + '
    ' + this.getTestResultList(result.errors) + '
' + + '
' + + '
' + + '

Passing Tests

' + + '
    ' + this.getTestResultList(result.passes) + '
' + + '
' + + '
'; + + target.innerHTML = template; + } - private getTestSummary(result: TestResult) { - return 'Total tests: ' + (result.passes.length + result.errors.length).toString() + '. ' + - 'Passed tests: ' + result.passes.length + '. ' + - 'Failed tests: ' + result.errors.length + '.'; - } + private getTestResult(result:TestResult) { + return result.errors.length === 0 ? 'Test Passed' : 'Test Failed'; + } - private getTestResultList(testResults: TestDescription[]) { - var list = ''; - var group = ''; - var isFirst = true; - for (var i = 0; i < testResults.length; ++i) { - var result = testResults[i]; - if (result.testName !== group) { - group = result.testName; - if (isFirst) { - isFirst = false; - } else { - list += ''; - } - list += '
  • ' + result.testName + '
      '; + private getTestSummary(result:TestResult) { + return 'Total tests: ' + (result.passes.length + result.errors.length).toString() + '. ' + + 'Passed tests: ' + result.passes.length + '. ' + + 'Failed tests: ' + result.errors.length + '.'; + } + + private getTestResultList(testResults:TestDescription[]) { + var list = ''; + var group = ''; + var isFirst = true; + for (var i = 0; i < testResults.length; ++i) { + var result = testResults[i]; + if (result.testName !== group) { + group = result.testName; + if (isFirst) { + isFirst = false; + } else { + list += '
    '; } - list += '
  • ' + result.funcName + '(): ' + this.encodeHtmlEntities(result.message) + '
  • '; + list += '
  • ' + result.testName + '
      '; } - return list + '
    '; + list += '
  • ' + result.funcName + '(): ' + this.encodeHtmlEntities(result.message) + '
  • '; } + return list + ''; + } - private encodeHtmlEntities(input: string) { - var entitiesToReplace = { '&': '&', '<': '<', '>': '>' }; - input.replace(/[&<>]/g, function (entity) { return entitiesToReplace[entity] || entity; }); - return input; - } + private encodeHtmlEntities(input:string) { + var entitiesToReplace = {'&': '&', '<': '<', '>': '>'}; + input.replace(/[&<>]/g, function (entity) { + return entitiesToReplace[entity] || entity; + }); + return input; } +} - export class TestContext { - setUp() { - } +export class TestContext { + setUp() { + } - tearDown() { + tearDown() { + } + + areIdentical(a:any, b:any):void { + if (a !== b) { + throw 'areIdentical failed when passed ' + + '{' + (typeof a) + '} "' + a + '" and ' + + '{' + (typeof b) + '} "' + b + '"'; } + } - areIdentical(a: any, b: any): void { - if (a !== b) { - throw 'areIdentical failed when passed ' + - '{' + (typeof a) + '} "' + a + '" and ' + - '{' + (typeof b) + '} "' + b + '"'; + areIdenticalArray(a:any, b:any):void { + + var r:boolean; + r = a.length == b.length; + if (r) { + for (var i:number = 0; i < a.length; i++) { + if (a[i] != b[i]) { + r = false; + break; + } } } - areIdenticalArray(a: any, b: any): void { - - var r:boolean; - r = a.length == b.length; - if(r){ - for(var i:number =0;i + + + + JavaScript ByteArray Test + + + + + +
    + + diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..2ce2cea --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "target": "ES5", + "module": "system", + "moduleResolution": "node", + "sourceMap": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "removeComments": true, + "noImplicitAny": false + }, + "exclude": [ + "tools", + "build", + "node_modules" + ] +} \ No newline at end of file