dimanche 25 janvier 2015

How to store incoming data efficiently in a (javascript) firefox addon?


Vote count:

0




Upon requesting a certain URL, I'd like to save the incoming markdown, transform it into HTML, then pass it on for display. If using an observer, I can get the channel, and set the channel's listener to my special "override" listener via nsiTraceableChannel, then pass on the data to the original listener for display, but I'm puzzled what to do at that point. The onDataAvailable method passes a nsiInputStream, which cannot be read from in javascript code. While I could wrap that in a nsiScriptableInputStream and read from that, that seems like it would introduce a lot of wrapping around a simple read operation that might repeat many times. I'd rather just read it all at once in nice enclosed binary code.


What I want to do is use NetUtils.asyncCopy to copy that input stream to a storage stream, and when that finishes transform the result of the storage stream into the stuff to pass the original listener. But wouldn't that keep calling my override listener with onDataAvailable too? The documentation says onDataAvalilable MUST read exactly that many bytes from the inputStream before returning, so I guess using nsiScriptableInputStream is mandatory? Would I just read from the scriptable input stream, then ignore and discard that, while the async copy continued in the background? Does asyncCopy replace my override listener with its own listener, which would be fine, or do they stack, which would be bad?


Ideally I'd want a thing that takes an output stream, and returns a stream listener for passing to nsiTraceableChannel.setInputStream, but I can't find anything like that, or even a list of what implements nsiStreamListener.



asked 26 secs ago







How to store incoming data efficiently in a (javascript) firefox addon?

Aucun commentaire:

Enregistrer un commentaire