On Apr 8, 2:18 pm, Christian Biesinger <[EMAIL PROTECTED]> wrote:
> NaReN wrote:
> > Well, primarily because it didn't work :) I gathered the open method
> > returns an nsIInputStream and I need to read its contents to look at
> > the data. I tied to do that but failed and was not too sure if that
> > was the right thing to do. Reading output data from an input stream
> > didn't sound like i was on the right track.
>
> I'm not sure what you mean with "output data", but input streams are the
> only kinds of streams you can read from. That's basically their definition.
>
> > Could you give me a few pointers on reading data from an
> > nsIInputStream ? The data returned by the HTTP request may be either
> > XML or text .
>
> So in JS this is slightly harder than in C++, but it's basically like
> this: (note that the code as I write it here is not very i18n-friendly,
> and would also fail for binary data)
>
> var stream = channel.open();
>
> var scriptableInputStream = Components.classes["@mozilla.org/
> scriptableinputstream;
> 1"].createInstance(Components.interfaces.nsIScriptableInputStream);
> scriptableInputStream.init(stream);
>
> var data = "";
> do {
> var str = scriptableInputStream.read(1024);
> data += str;
> } while (str.length > 0);
>
> --
> All the world's a stage,
> And all the men and women merely players:
> They have their exits and their entrances;
> And one man in his time plays many parts, [...] --W. Shakespeare
That was great, thanks !
_______________________________________________
dev-tech-xpcom mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-xpcom