Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I would suggest two other (fast) options:</p> <ol> <li><p>First, you can use <strong>ADODB.Recordset</strong> to convert the byte array into a string. I would guess that this object is more common that ADODB.Stream, which is often disabled for security reasons. This option is VERY fast, less than <em>30ms</em> for a 500kB file.</p></li> <li><p>Second, if the Recordset component is not accessible, there is a <strong>trick to access the byte array data from Javascript</strong>. Send your xhr.responseBody to VBScript, pass it through any VBScript string function such as CStr (takes no time), and return it to JS. You will get a weird string with bytes concatenated into 16-bit unicode (in reverse). You can then convert this string quickly into a usable bytestring through a <strong>regular expression</strong> with dictionary-based replacement. Takes about <em>1s</em> for 500kB.</p></li> </ol> <p>For comparison, the byte-by-byte conversion through loops takes <em>several minutes</em> for this same 500kB file, so it's a no-brainer :) Below the code I have been using, to insert into your header. Then call the function <em>ieGetBytes</em> with your xhr.responseBody.</p> <pre><code>&lt;!--[if IE]&gt; &lt;script type="text/vbscript"&gt; 'Best case scenario when the ADODB.Recordset object exists 'We will do the existence test in Javascript (see after) 'Extremely fast, about 25ms for a 500kB file Function ieGetBytesADO(byteArray) Dim recordset Set recordset = CreateObject("ADODB.Recordset") With recordset .Fields.Append "temp", 201, LenB(byteArray) .Open .AddNew .Fields("temp").AppendChunk byteArray .Update End With ieGetBytesADO = recordset("temp") recordset.Close Set recordset = Nothing End Function 'Trick to return a Javascript-readable string from a VBScript byte array 'Yet the string is not usable as such by Javascript, since the bytes 'are merged into 16-bit unicode characters. Last character missing if odd length. Function ieRawBytes(byteArray) ieRawBytes = CStr(byteArray) End Function 'Careful the last character is missing in case of odd file length 'We Will call the ieLastByte function (below) from Javascript 'Cannot merge directly within ieRawBytes as the final byte would be duplicated Function ieLastChr(byteArray) Dim lastIndex lastIndex = LenB(byteArray) if lastIndex mod 2 Then ieLastChr = Chr( AscB( MidB( byteArray, lastIndex, 1 ) ) ) Else ieLastChr = "" End If End Function &lt;/script&gt; &lt;script type="text/javascript"&gt; try { // best case scenario, the ADODB.Recordset object exists // we can use the VBScript ieGetBytes function to transform a byte array into a string var ieRecordset = new ActiveXObject('ADODB.Recordset'); var ieGetBytes = function( byteArray ) { return ieGetBytesADO(byteArray); } ieRecordset = null; } catch(err) { // no ADODB.Recordset object, we will do the conversion quickly through a regular expression // initializes for once and for all the translation dictionary to speed up our regexp replacement function var ieByteMapping = {}; for ( var i = 0; i &lt; 256; i++ ) { for ( var j = 0; j &lt; 256; j++ ) { ieByteMapping[ String.fromCharCode( i + j * 256 ) ] = String.fromCharCode(i) + String.fromCharCode(j); } } // since ADODB is not there, we replace the previous VBScript ieGetBytesADO function with a regExp-based function, // quite fast, about 1.3 seconds for 500kB (versus several minutes for byte-by-byte loops over the byte array) var ieGetBytes = function( byteArray ) { var rawBytes = ieRawBytes(byteArray), lastChr = ieLastChr(byteArray); return rawBytes.replace(/[\s\S]/g, function( match ) { return ieByteMapping[match]; }) + lastChr; } } &lt;/script&gt; &lt;![endif]--&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload