-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I found the solution to my problem using binaryinputstream and
binaryoutputstream components.


                                var channel=request.channel;
                                var stream=channel.open();
                                var fos =
Components.classes["@mozilla.org/network/file-output-stream;1"].
                            
createInstance(Components.interfaces.nsIFileOutputStream);
                                var 
length=request.getResponseHeader("content-length");
                                fos.init(file,0x02 | 0x08 | 0x20, 0644, 0);
                                var bistream = 
Components.classes["@mozilla.org/binaryinputstream;1"].
                        
createInstance(Components.interfaces.nsIBinaryInputStream);
                                bistream.setInputStream(stream);
                                var bostream = 
Components.classes["@mozilla.org/binaryoutputstream;1"].
                        
createInstance(Components.interfaces.nsIBinaryOutputStream);
                                bostream.setOutputStream(fos);
                                var n=0;
                                length=parseInt(length);
                                while(n<length) {
                                        var 
ba=bistream.readByteArray(bistream.available());
                                        bostream.writeByteArray(ba,ba.length);
                                        n+=ba.length;
                                }                                       
                                fos.flush();
                                fos.close();
                                stream.close();


Michel Gutierrez wrote:
> 
> hi,
> 
> in an extension implemented in javascript, i would like to use the
> nsIXmlHttpRequest object to query data from an url. based on the
> returned content-type, i would like to either parse the returned file
> and do some stuff, or save the binary data into a file.
> 
> i cannot find a way to save the binary data. the
> @mozilla.org/network/file-output-stream;1 component seems not to
> implement writeFrom method and i'm running out of ideas.
> 
> does anybody have some trick for doing so ?
> 
> thanks,
> /mig
> 
> 
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFeCPmtMkIv0/ruZgRAoCDAKCNCbAA+RSUEIQ6OCGMMO3oGHdDpACeLFut
EZy/9QU/5OqvFNpmfKHS4lI=
=/aSh
-----END PGP SIGNATURE-----
_______________________________________________
dev-tech-xpcom mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-xpcom

Reply via email to