Opening / Reading binary files 
Author Message
 Opening / Reading binary files

Hi Raman,

Not using standard FSO stuff.
However, as a coinsidence I am in the final stages
of completing a Binary object for Jscript just to accomplish this
thing. It internally uses ADODB.Stream/RecordSet and  the
Msxml2.DOMDocument interfaces to handle the conversion/file stuff.
no 3rd party software involved.

Intended for use in a WSH environment mainly, but it should run fine hosted
in a
MSIE 5+ and an ASP environment too as long as ADODB 2.5+ and Msxml2
is present.

It's currently incorporated in a script-lib project I am working on, Soya,
but it can easily be made self contained. want a testdrive. just let me
know.

I knocked this one up mainly for 4 purposes.
1. xmlhttp binaryresponse -> binary file
2. binary file -> base64/hex encoded string
3. ascii string -> binary file. (this one rocks! ..eventhough its slow)
4. binary file -> hex -> custom manipulation -> back to binfile

usage.
1.
 var oHTTP = new ActiveXObject("microsoft.xmlhttp");
 oHTTP.Open("GET", " http://www.*-*-*.com/ ;, false);
 oHTTP.Send();
 var oBin = new Soya.IO.Binary(oHTTP.responseBody);
 oBin.save("sunet.gif");
--
2.
 var oBin = new Soya.IO.Binary();
 oBin.load("sunet.gif");
 var sBase64Image = oBin.toBase64();
--
3.
 var sGif =
 '\x47\x49\x46\x38\x39\x61\x10\x00\x10\x00\xb3\x0d'+
 '\x00\x16\x6e\xa7\xa8\xc8\xdd\x8b\xb7\xd3\xfd\xfd'+
 '\xfd\x6e\xa5\xc8\x01\x5e\x9f\xd5\xe4\xef\xc4\xda'+
 '\xe8\x60\x9d\xc4\x35\x82\xb4\x4b\x8f\xbb\x57\x98'+
 '\xc1\xe8\xf0\xf5\x00\x00\x00\x00\x00\x00\x00\x00'+
 '\x00\x21\xf9\x04\x01\x00\x00\x0d\x00\x2c\x00\x00'+
 '\x00\x00\x10\x00\x10\x00\x40\x04\x74\xb0\xc9\x49'+
 '\x2b\x2d\xe5\x8c\x54\x58\x28\x88\x41\x54\x85\x30'+
 '\x18\x06\x03\x08\x81\x30\x01\x40\x02\x14\xc1\x30'+
 '\x20\xca\xf0\x59\xcd\x91\x24\x02\x82\x69\x70\x58'+
 '\x90\x4c\x80\xc5\x06\x30\x30\x4a\x00\x04\xdb\xad'+
 '\x10\x25\x00\x0e\x87\x51\xe5\x53\x00\x48\x58\x3c'+
 '\x8b\x40\xa1\x20\x1c\x2a\x0b\x40\xcd\x96\xfa\x20'+
 '\x48\xb5\x15\x03\x24\xb2\x94\x06\x0a\x26\x81\xd6'+
 '\x9a\x14\x80\x27\x18\x3a\x54\x0c\x4e\x6a\x03\x0c'+
 '\x04\x0a\x1a\x89\x0c\x37\x01\x7e\x5d\x7f\x02\x1c'+
 '\x92\x90\x61\x98\x11\x00\x3b';

 var oBin = new Soya.IO.Binary(sGif);
oBin.save("surprise.gif");

thomas.
--
___________________________________________________

  http://www.*-*-*.com/ | http://www.*-*-*.com/
________________________________S_a_l_t_s_t_o_r_m____


Quote:
> Is there a way to open and read binary files using
> JScript? I know that the FSO object supports text files.
> However, it's not very clear on the support for binary
> files.

> Thanks,
> Raman.



Sun, 27 Jun 2004 07:47:37 GMT  
 Opening / Reading binary files
be sure to post an ANNC when you're ready :)


Sun, 27 Jun 2004 08:22:40 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. open a binary file for reading/writing

2. Reading binary files in VBScript

3. Reading binary files in VBScript

4. can vbscript read BINARY files?

5. Reading in a binary file...

6. Reading binary file

7. Reading binary file using VBScript

8. reading binary file in vbscript

9. How to read binary files?

10. Reading binary data in a postscript file

11. How can I read binary file???

12. Reading the Binary file using FileSystem Object

 

 
Powered by phpBB® Forum Software