Bug 1885602 - Part 2: Add a MozillaAccountMenuButton composable for the menu redesign...
[gecko.git] / dom / xhr / tests / temporaryFileBlob.sjs
blob151c05a231aa1999e2aa3f72020e940b389d4b0e
1 const CC = Components.Constructor;
3 const BinaryInputStream = CC(
4   "@mozilla.org/binaryinputstream;1",
5   "nsIBinaryInputStream",
6   "setInputStream"
7 );
8 const BinaryOutputStream = CC(
9   "@mozilla.org/binaryoutputstream;1",
10   "nsIBinaryOutputStream",
11   "setOutputStream"
13 const Timer = CC("@mozilla.org/timer;1", "nsITimer", "initWithCallback");
15 function handleRequest(request, response) {
16   var bodyStream = new BinaryInputStream(request.bodyInputStream);
17   var bodyBytes = [];
18   let bodyAvail;
19   while ((bodyAvail = bodyStream.available()) > 0) {
20     Array.prototype.push.apply(bodyBytes, bodyStream.readByteArray(bodyAvail));
21   }
23   var bos = new BinaryOutputStream(response.bodyOutputStream);
25   response.processAsync();
27   var part = bodyBytes.splice(0, 256);
28   bos.writeByteArray(part);
30   response.timer1 = new Timer(
31     function () {
32       bos.writeByteArray(bodyBytes);
33     },
34     1000,
35     Ci.nsITimer.TYPE_ONE_SHOT
36   );
38   response.timer2 = new Timer(
39     function () {
40       response.finish();
41     },
42     2000,
43     Ci.nsITimer.TYPE_ONE_SHOT
44   );