[Pkg-javascript-commits] [node-stream-http] 119/208: Use to-arraybuffer instead of manual conversion

Bastien Roucariès rouca at moszumanska.debian.org
Sun Aug 13 13:39:34 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-stream-http.

commit 6bab67d17ae254c202993a16d90b9cbc15cacd78
Author: John Hiesey <john at hiesey.com>
Date:   Wed Jan 13 03:40:41 2016 +0100

    Use to-arraybuffer instead of manual conversion
    
    This fixes some more edge cases when converting from a Buffer to
    an ArrayBuffer.
    
    Additionally, compared v2.0.5, this avoids an unnecessary copy
    when sending data in a request body.
---
 lib/request.js | 11 ++---------
 package.json   |  1 +
 2 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/lib/request.js b/lib/request.js
index f01c0b2..1dafc64 100644
--- a/lib/request.js
+++ b/lib/request.js
@@ -3,6 +3,7 @@ var capability = require('./capability')
 var inherits = require('inherits')
 var response = require('./response')
 var stream = require('stream')
+var toArrayBuffer = require('to-arraybuffer')
 
 var IncomingMessage = response.IncomingMessage
 var rStates = response.readyStates
@@ -96,15 +97,7 @@ ClientRequest.prototype._onFinish = function () {
 	if (opts.method === 'POST' || opts.method === 'PUT' || opts.method === 'PATCH') {
 		if (capability.blobConstructor) {
 			body = new global.Blob(self._body.map(function (buffer) {
-				if (buffer instanceof Uint8Array) {
-					return buffer
-				} else {
-					var buf = new Uint8Array(buffer.length)
-					for (var i = 0, len = buf.length; i < len; i++) {
-						buf[i] = buffer[i]
-					}
-					return buf
-				}
+				return toArrayBuffer(buffer)
 			}), {
 				type: (headersObj['content-type'] || {}).value || ''
 			})
diff --git a/package.json b/package.json
index f93f460..d6b4007 100644
--- a/package.json
+++ b/package.json
@@ -25,6 +25,7 @@
   "dependencies": {
     "builtin-status-codes": "^1.0.0",
     "inherits": "^2.0.1",
+    "to-arraybuffer": "^1.0.0",
     "xtend": "^4.0.0"
   },
   "devDependencies": {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-stream-http.git



More information about the Pkg-javascript-commits mailing list