Note that there are some explanatory texts on larger screens.

plurals
  1. POgziping strings in a firefox extension
    text
    copied!<p>from this blog <a href="http://blog.mozilla.org/nfroyd/2012/01/26/compressing-strings-in-js/" rel="nofollow">http://blog.mozilla.org/nfroyd/2012/01/26/compressing-strings-in-js/</a> it seems like it should be possible, but I'm having trouble implementing (basically as is).</p> <p>my code is</p> <pre><code>function Accumulator() { this.buffer = ""; }; Accumulator.prototype = { buffer: null, onStartRequest: function(request, context) {}, onStopRequest: function(request, context, statusCode) {}, onDataAvailable: function(request, context, inputStream, offset, count) { var stream = Components.classes["@mozilla.org/binaryinputstream;1"].createInstance(Components.interfaces.nsIBinaryInputStream); stream.setInputStream(inputStream); var input = stream.readByteArray(count); this.buffer += String.fromCharCode.apply(input); } }; function compress(string) { var accumulator = new Accumulator(); var converter = Components.classes["@mozilla.org/streamconv;1?from=uncompressed&amp;to=gzip"].createInstance(Components.interfaces.nsIStreamConverter); // More respecifying input/output types. converter.asyncConvertData("uncompressed", "gzip", accumulator, null); // Oh, that method doesn't actually convert anything, it just prepares // the instance for doing conversion. var stream = Components.classes["@mozilla.org/io/string-input-stream;1"].createInstance(Components.interfaces.nsIStringInputStream); stream.data = string; converter.onStartRequest(null, null); converter.onDataAvailable(null, null, stream, 0, string.length); converter.onStopRequest(null, null, 201 /* 417 */); return accumulator.buffer; }; </code></pre> <p>but when I use it, I'm getting an error that converter.onRequestStart is not a function.</p> <p>wondering if I'm doing something obviously wrong?</p> <p>edit: </p> <p>1) fixing some obvious mistakes. Ci I didn't catch originally, it's Components.interfaces.</p> <p>2) original code seemed to have onRequestStart/Stop backwards, they should be onStartRequest/onStopRequest.</p> <p>with those changes, no longer throws any errors, but also returns an empty string, so nothing seems to be happening. :(</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload