temporaryFileBlob.sjs (1062B)
1 const CC = Components.Constructor; 2 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" 12 ); 13 const Timer = CC("@mozilla.org/timer;1", "nsITimer", "initWithCallback"); 14 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 } 22 23 var bos = new BinaryOutputStream(response.bodyOutputStream); 24 25 response.processAsync(); 26 27 var part = bodyBytes.splice(0, 256); 28 bos.writeByteArray(part); 29 30 response.timer1 = new Timer( 31 function () { 32 bos.writeByteArray(bodyBytes); 33 }, 34 1000, 35 Ci.nsITimer.TYPE_ONE_SHOT 36 ); 37 38 response.timer2 = new Timer( 39 function () { 40 response.finish(); 41 }, 42 2000, 43 Ci.nsITimer.TYPE_ONE_SHOT 44 ); 45 }