tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

server_file_upload.sjs (659B)


      1 const CC = Components.Constructor;
      2 const BinaryInputStream = CC(
      3   "@mozilla.org/binaryinputstream;1",
      4   "nsIBinaryInputStream",
      5   "setInputStream"
      6 );
      7 const BinaryOutputStream = CC(
      8   "@mozilla.org/binaryoutputstream;1",
      9   "nsIBinaryOutputStream",
     10   "setOutputStream"
     11 );
     12 
     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));
     18   }
     19 
     20   var bos = new BinaryOutputStream(response.bodyOutputStream);
     21   bos.writeByteArray(bodyBytes, bodyBytes.length);
     22 }