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 <[email protected]> Authored: Tue Oct 21 15:47:30 2014 -0400 Committer: Andrew Grieve <[email protected]> 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: [email protected] For additional commands, e-mail: [email protected]
