diff options
Diffstat (limited to 'js/binaryXHR.js')
-rw-r--r-- | js/binaryXHR.js | 69 |
1 files changed, 46 insertions, 23 deletions
diff --git a/js/binaryXHR.js b/js/binaryXHR.js index d91ad72..e4e7515 100644 --- a/js/binaryXHR.js +++ b/js/binaryXHR.js | |||
@@ -37,6 +37,8 @@ function BinaryFile(strData, iDataOffset, iDataLength) { | |||
37 | var doubleMantExpLo=Math.pow(2,-52); | 37 | var doubleMantExpLo=Math.pow(2,-52); |
38 | var doubleMantExpFast=Math.pow(2,-20); | 38 | var doubleMantExpFast=Math.pow(2,-20); |
39 | 39 | ||
40 | var switch_endian = false; | ||
41 | |||
40 | this.getRawData = function() { | 42 | this.getRawData = function() { |
41 | return data; | 43 | return data; |
42 | } | 44 | } |
@@ -57,6 +59,13 @@ function BinaryFile(strData, iDataOffset, iDataLength) { | |||
57 | throw new InvalidBinaryFile("Unsupported type " + (typeof strData)); | 59 | throw new InvalidBinaryFile("Unsupported type " + (typeof strData)); |
58 | } | 60 | } |
59 | 61 | ||
62 | this.getEndianByteAt = function(iOffset,width,delta) { | ||
63 | if (this.switch_endian) | ||
64 | return this.getByteAt(iOffset+width-delta-1); | ||
65 | else | ||
66 | return this.getByteAt(iOffset+delta); | ||
67 | } | ||
68 | |||
60 | this.getLength = function() { | 69 | this.getLength = function() { |
61 | return dataLength; | 70 | return dataLength; |
62 | } | 71 | } |
@@ -70,7 +79,7 @@ function BinaryFile(strData, iDataOffset, iDataLength) { | |||
70 | } | 79 | } |
71 | 80 | ||
72 | this.getShortAt = function(iOffset) { | 81 | this.getShortAt = function(iOffset) { |
73 | var iShort = (this.getByteAt(iOffset + 1) << 8) + this.getByteAt(iOffset) | 82 | var iShort = (this.getEndianByteAt(iOffset,2,1) << 8) + this.getEndianByteAt(iOffset,2,0) |
74 | if (iShort < 0) iShort += 65536; | 83 | if (iShort < 0) iShort += 65536; |
75 | return iShort; | 84 | return iShort; |
76 | } | 85 | } |
@@ -82,10 +91,10 @@ function BinaryFile(strData, iDataOffset, iDataLength) { | |||
82 | return iUShort; | 91 | return iUShort; |
83 | } | 92 | } |
84 | this.getLongAt = function(iOffset) { | 93 | this.getLongAt = function(iOffset) { |
85 | var iByte1 = this.getByteAt(iOffset), | 94 | var iByte1 = this.getEndianByteAt(iOffset,4,0), |
86 | iByte2 = this.getByteAt(iOffset + 1), | 95 | iByte2 = this.getEndianByteAt(iOffset,4,1), |
87 | iByte3 = this.getByteAt(iOffset + 2), | 96 | iByte3 = this.getEndianByteAt(iOffset,4,2), |
88 | iByte4 = this.getByteAt(iOffset + 3); | 97 | iByte4 = this.getEndianByteAt(iOffset,4,3); |
89 | 98 | ||
90 | var iLong = (((((iByte4 << 8) + iByte3) << 8) + iByte2) << 8) + iByte1; | 99 | var iLong = (((((iByte4 << 8) + iByte3) << 8) + iByte2) << 8) + iByte1; |
91 | if (iLong < 0) iLong += 4294967296; | 100 | if (iLong < 0) iLong += 4294967296; |
@@ -117,14 +126,14 @@ function BinaryFile(strData, iDataOffset, iDataLength) { | |||
117 | 126 | ||
118 | // Added | 127 | // Added |
119 | this.getDoubleAt = function(iOffset) { | 128 | this.getDoubleAt = function(iOffset) { |
120 | var iByte1 = this.getByteAt(iOffset), | 129 | var iByte1 = this.getEndianByteAt(iOffset,8,0), |
121 | iByte2 = this.getByteAt(iOffset + 1), | 130 | iByte2 = this.getEndianByteAt(iOffset,8,1), |
122 | iByte3 = this.getByteAt(iOffset + 2), | 131 | iByte3 = this.getEndianByteAt(iOffset,8,2), |
123 | iByte4 = this.getByteAt(iOffset + 3), | 132 | iByte4 = this.getEndianByteAt(iOffset,8,3), |
124 | iByte5 = this.getByteAt(iOffset + 4), | 133 | iByte5 = this.getEndianByteAt(iOffset,8,4), |
125 | iByte6 = this.getByteAt(iOffset + 5), | 134 | iByte6 = this.getEndianByteAt(iOffset,8,5), |
126 | iByte7 = this.getByteAt(iOffset + 6), | 135 | iByte7 = this.getEndianByteAt(iOffset,8,6), |
127 | iByte8 = this.getByteAt(iOffset + 7); | 136 | iByte8 = this.getEndianByteAt(iOffset,8,7); |
128 | var iSign=iByte8 >> 7; | 137 | var iSign=iByte8 >> 7; |
129 | var iExpRaw=((iByte8 & 0x7F)<< 4) + (iByte7 >> 4); | 138 | var iExpRaw=((iByte8 & 0x7F)<< 4) + (iByte7 >> 4); |
130 | var iMantHi=((((((iByte7 & 0x0F) << 8) + iByte6) << 8) + iByte5) << 8) + iByte4; | 139 | var iMantHi=((((((iByte7 & 0x0F) << 8) + iByte6) << 8) + iByte5) << 8) + iByte4; |
@@ -141,10 +150,10 @@ function BinaryFile(strData, iDataOffset, iDataLength) { | |||
141 | // added | 150 | // added |
142 | // Extracts only 4 bytes out of 8, loosing in precision (20 bit mantissa) | 151 | // Extracts only 4 bytes out of 8, loosing in precision (20 bit mantissa) |
143 | this.getFastDoubleAt = function(iOffset) { | 152 | this.getFastDoubleAt = function(iOffset) { |
144 | var iByte5 = this.getByteAt(iOffset + 4), | 153 | var iByte5 = this.getEndianByteAt(iOffset,8,4), |
145 | iByte6 = this.getByteAt(iOffset + 5), | 154 | iByte6 = this.getEndianByteAt(iOffset,8,5), |
146 | iByte7 = this.getByteAt(iOffset + 6), | 155 | iByte7 = this.getEndianByteAt(iOffset,8,6), |
147 | iByte8 = this.getByteAt(iOffset + 7); | 156 | iByte8 = this.getEndianByteAt(iOffset,8,7); |
148 | var iSign=iByte8 >> 7; | 157 | var iSign=iByte8 >> 7; |
149 | var iExpRaw=((iByte8 & 0x7F)<< 4) + (iByte7 >> 4); | 158 | var iExpRaw=((iByte8 & 0x7F)<< 4) + (iByte7 >> 4); |
150 | var iMant=((((iByte7 & 0x0F) << 8) + iByte6) << 8) + iByte5; | 159 | var iMant=((((iByte7 & 0x0F) << 8) + iByte6) << 8) + iByte5; |
@@ -190,10 +199,17 @@ function FetchBinaryURL(url) { | |||
190 | } | 199 | } |
191 | request.send(null); | 200 | request.send(null); |
192 | 201 | ||
193 | var response=request.responseBody; | 202 | var response=this.responseText; |
194 | if (response==undefined){ // responseBody is non standard, but the only way to make it work in IE | 203 | try { |
195 | response=request.responseText; | 204 | // for older IE versions, the value in responseText is not usable |
205 | if (IEBinary_getLength(this.responseBody)>0) { | ||
206 | // will get here only for older verson of IE | ||
207 | response=this.responseBody; | ||
208 | } | ||
209 | } catch (err) { | ||
210 | // not IE, do nothing | ||
196 | } | 211 | } |
212 | |||
197 | var bf=new BinaryFile(response); | 213 | var bf=new BinaryFile(response); |
198 | return bf; | 214 | return bf; |
199 | } | 215 | } |
@@ -208,10 +224,17 @@ function FetchBinaryURL(url) { | |||
208 | function FetchBinaryURLAsync(url, callback, callback_arg) { | 224 | function FetchBinaryURLAsync(url, callback, callback_arg) { |
209 | var callback_wrapper = function() { | 225 | var callback_wrapper = function() { |
210 | if(this.readyState == 4) { | 226 | if(this.readyState == 4) { |
211 | var response=this.responseBody; | 227 | var response=this.responseText; |
212 | if (response==undefined){ // responseBody is non standard, but the only way to make it work in IE | 228 | try { |
213 | response=this.responseText; | 229 | // for older IE versions, the value in responseText is not usable |
230 | if (IEBinary_getLength(this.responseBody)>0) { | ||
231 | // will get here only for older verson of IE | ||
232 | response=this.responseBody; | ||
233 | } | ||
234 | } catch (err) { | ||
235 | // not IE, do nothing | ||
214 | } | 236 | } |
237 | |||
215 | var bf=new BinaryFile(response); | 238 | var bf=new BinaryFile(response); |
216 | if (callback_arg!=null) { | 239 | if (callback_arg!=null) { |
217 | callback(bf,callback_arg); | 240 | callback(bf,callback_arg); |