i using following code read in binary file in vbscript , store in byte array access javascript , copy js array, sneaky way (the way!) i've found of reading binary data in js.
function readbinaryfile(filename) dim instream,buff set instream=createobject("adodb.stream") instream.open instream.type=1 instream.loadfromfile filename buff=instream.read() instream.close dim bytearray() dim dim len len = lenb(buff) redim bytearray(len) = 1 len bytearray(i-1) = ascb(midb(buff, i, 1)) next readbinaryfile=bytearray end function
it appears work expected, problem being seems extremely slow. example, reading in 300kb file can take on 2 minutes. expecting read files around 2meg.
could explain why such slow operation , if there's can speed up?
thanks.
the problem loop. try using disconnected recordset conversion:
function rsbinarytostring(xbinary) 'antonin foller, http://www.motobit.com 'rsbinarytostring converts binary data (vt_ui1 | vt_array or multibyte string) 'to string (bstr) using ado recordset dim binary 'multibyte data must converted vt_ui1 | vt_array first. if vartype(xbinary)=8 binary = multibytetobinary(xbinary) else binary = xbinary dim rs, lbinary const adlongvarchar = 201 set rs = createobject("adodb.recordset") lbinary = lenb(binary) if lbinary>0 rs.fields.append "mbinary", adlongvarchar, lbinary rs.open rs.addnew rs("mbinary").appendchunk binary rs.update rsbinarytostring = rs("mbinary") else rsbinarytostring = "" end if end function function multibytetobinary(multibyte) '© 2000 antonin foller, http://www.motobit.com ' multibytetobinary converts multibyte string real binary data (vt_ui1 | vt_array) ' using recordset dim rs, lmultibyte, binary const adlongvarbinary = 205 set rs = createobject("adodb.recordset") lmultibyte = lenb(multibyte) if lmultibyte>0 rs.fields.append "mbinary", adlongvarbinary, lmultibyte rs.open rs.addnew rs("mbinary").appendchunk multibyte & chrb(0) rs.update binary = rs("mbinary").getchunk(lmultibyte) end if multibytetobinary = binary end function
in case have readbinaryfile
return "ascii contents" of file , use instead of array: readbinaryfile = rsbinarytostring(buf)
Comments
Post a Comment