Bug 1708422: part 14) Extend documentation of `mozInlineSpellChecker::SpellCheckerTim...
[gecko.git] / dom / xhr / tests / temporaryFileBlob.sjs
blob814c06d1ed4eec2ee2f49160701b950624a9b0b8
1 const CC = Components.Constructor;
3 const BinaryInputStream = CC("@mozilla.org/binaryinputstream;1",
4                              "nsIBinaryInputStream",
5                              "setInputStream");
6 const BinaryOutputStream = CC("@mozilla.org/binaryoutputstream;1",
7                               "nsIBinaryOutputStream",
8                               "setOutputStream");
9 const Timer = CC("@mozilla.org/timer;1",
10                  "nsITimer",
11                  "initWithCallback");
13 function handleRequest(request, response) {
14   var bodyStream = new BinaryInputStream(request.bodyInputStream);
15   var bodyBytes = [];
16   while ((bodyAvail = bodyStream.available()) > 0)
17     Array.prototype.push.apply(bodyBytes, bodyStream.readByteArray(bodyAvail));
19   var bos = new BinaryOutputStream(response.bodyOutputStream);
21   response.processAsync();
23   var part = bodyBytes.splice(0, 256);
24   bos.writeByteArray(part);
26   response.timer1 = new Timer(function(timer) {
27     bos.writeByteArray(bodyBytes);
28   }, 1000, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
30   response.timer2 = new Timer(function(timer) {
31     response.finish();
32   }, 2000, Components.interfaces.nsITimer.TYPE_ONE_SHOT);