From fcd7fa1d7a3d621b2788057b53f3c4878ff7b9c4 Mon Sep 17 00:00:00 2001 From: Jacob Seidelin Date: Fri, 6 Feb 2009 23:05:27 +0000 Subject: binaryajax.js 0.1.5 found at https://gist.githubusercontent.com/zinoviev/4981185/raw/8ad77274b3ca06538da0dbbcef3807ca5d065244/gistfile1.js --- binaryajax.js | 235 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 235 insertions(+) create mode 100644 binaryajax.js diff --git a/binaryajax.js b/binaryajax.js new file mode 100644 index 0000000..f674d9c --- /dev/null +++ b/binaryajax.js @@ -0,0 +1,235 @@ + +/* + * Binary Ajax 0.1.5 + * Copyright (c) 2008 Jacob Seidelin, cupboy@gmail.com, http://blog.nihilogic.dk/ + * MIT License [http://www.opensource.org/licenses/mit-license.php] + */ + + +var BinaryFile = function(strData, iDataOffset, iDataLength) { + var data = strData; + var dataOffset = iDataOffset || 0; + var dataLength = 0; + + this.getRawData = function() { + return data; + } + + if (typeof strData == "string") { + dataLength = iDataLength || data.length; + + this.getByteAt = function(iOffset) { + return data.charCodeAt(iOffset + dataOffset) & 0xFF; + } + } else if (typeof strData == "unknown") { + dataLength = iDataLength || IEBinary_getLength(data); + + this.getByteAt = function(iOffset) { + return IEBinary_getByteAt(data, iOffset + dataOffset); + } + } + + this.getLength = function() { + return dataLength; + } + + this.getSByteAt = function(iOffset) { + var iByte = this.getByteAt(iOffset); + if (iByte > 127) + return iByte - 256; + else + return iByte; + } + + this.getShortAt = function(iOffset, bBigEndian) { + var iShort = bBigEndian ? + (this.getByteAt(iOffset) << 8) + this.getByteAt(iOffset + 1) + : (this.getByteAt(iOffset + 1) << 8) + this.getByteAt(iOffset) + if (iShort < 0) iShort += 65536; + return iShort; + } + this.getSShortAt = function(iOffset, bBigEndian) { + var iUShort = this.getShortAt(iOffset, bBigEndian); + if (iUShort > 32767) + return iUShort - 65536; + else + return iUShort; + } + this.getLongAt = function(iOffset, bBigEndian) { + var iByte1 = this.getByteAt(iOffset), + iByte2 = this.getByteAt(iOffset + 1), + iByte3 = this.getByteAt(iOffset + 2), + iByte4 = this.getByteAt(iOffset + 3); + + var iLong = bBigEndian ? + (((((iByte1 << 8) + iByte2) << 8) + iByte3) << 8) + iByte4 + : (((((iByte4 << 8) + iByte3) << 8) + iByte2) << 8) + iByte1; + if (iLong < 0) iLong += 4294967296; + return iLong; + } + this.getSLongAt = function(iOffset, bBigEndian) { + var iULong = this.getLongAt(iOffset, bBigEndian); + if (iULong > 2147483647) + return iULong - 4294967296; + else + return iULong; + } + this.getStringAt = function(iOffset, iLength) { + var aStr = []; + for (var i=iOffset,j=0;i\r\n" + + "Function IEBinary_getByteAt(strBinary, iOffset)\r\n" + + " IEBinary_getByteAt = AscB(MidB(strBinary,iOffset+1,1))\r\n" + + "End Function\r\n" + + "Function IEBinary_getLength(strBinary)\r\n" + + " IEBinary_getLength = LenB(strBinary)\r\n" + + "End Function\r\n" + + "\r\n" +); -- cgit v1.2.3-2-g168b