You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2014/10/25 03:26:27 UTC

[09/17] git commit: Fix /deletefiles not working when deleting more than ~10 files.

Fix /deletefiles not working when deleting more than ~10 files.

HttpRequest.readEntireBody() was completely broken :(


Project: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/commit/7f7279a1
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/7f7279a1
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/7f7279a1

Branch: refs/heads/master
Commit: 7f7279a1278c0fc35ff7119487f3566b930cff2b
Parents: bbefd2a
Author: Andrew Grieve <ag...@chromium.org>
Authored: Tue Oct 21 15:47:30 2014 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Fri Oct 24 21:26:07 2014 -0400

----------------------------------------------------------------------
 www/cdvah/js/HttpServer.js | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/7f7279a1/www/cdvah/js/HttpServer.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/HttpServer.js b/www/cdvah/js/HttpServer.js
index 2d7244c..ed9a30e 100644
--- a/www/cdvah/js/HttpServer.js
+++ b/www/cdvah/js/HttpServer.js
@@ -85,20 +85,27 @@
         };
 
         HttpRequest.prototype.readEntireBody = function() {
+            var self = this;
             var byteArray = null;
             var soFar = 0;
-            var self = this;
             function handleChunk(chunk) {
-                if (byteArray) {
-                    byteArray.set(chunk, soFar);
-                    soFar += chunk.byteLength;
-                }
+                byteArray.set(new Uint8Array(chunk), soFar);
+                soFar += chunk.byteLength;
+
                 if (self.bytesRemaining === 0) {
-                    return byteArray ? byteArray.buffer : chunk;
+                    return byteArray.buffer;
                 }
                 return self.readChunk().then(handleChunk);
             }
-            return this.readChunk().then(handleChunk);
+            return this.readChunk().then(function(chunk) {
+                // Avoid array copy if there's only one chunk.
+                if (self.bytesRemaining === 0) {
+                    return chunk;
+                }
+                // Otherwise, allocate the buffer based on Content-Length.
+                byteArray = new Uint8Array(self.bytesRemaining + chunk.byteLength);
+                return handleChunk(chunk);
+            });
         };
 
         HttpRequest.prototype.readChunk = function(/* optional */maxChunkSize) {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org