[Pkg-javascript-commits] [node-stream-browserify] 21/44: checks for typed array that work if typed arrays aren't available

Bastien Roucariès rouca at moszumanska.debian.org
Sun Aug 13 14:18:42 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-browserify.

commit b2ffc5343f4bdc96ec66d4914d2f13db5d908077
Author: James Halliday <mail at substack.net>
Date:   Fri Dec 20 00:40:49 2013 -0800

    checks for typed array that work if typed arrays aren't available
---
 package.json |  4 ++--
 writable.js  | 14 ++++++++++++--
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/package.json b/package.json
index 7ae1a68..c624744 100644
--- a/package.json
+++ b/package.json
@@ -8,8 +8,8 @@
     "process": "~0.5.1"
   },
   "devDependencies": {
-    "tape": "~2.3.2",
-    "typedarray": "0.0.5"
+    "typedarray": "~0.0.5",
+    "tape": "~2.3.2"
   },
   "scripts": {
     "test": "tape test/*.js"
diff --git a/writable.js b/writable.js
index cece221..e045b28 100644
--- a/writable.js
+++ b/writable.js
@@ -26,6 +26,16 @@
 module.exports = Writable;
 Writable.WritableState = WritableState;
 
+var TA = require('typedarray');
+var isUint8Array = typeof Uint8Array !== 'undefined'
+  ? function (x) { return x instanceof Uint8Array }
+  : function () { return false }
+;
+var isArrayBuffer = typeof ArrayBuffer !== 'undefined'
+  ? function (x) { return x instanceof ArrayBuffer }
+  : function () { return false }
+;
+
 var inherits = require('inherits');
 var Stream = require('./index.js');
 var setImmediate = require('process/browser.js').nextTick;
@@ -167,9 +177,9 @@ Writable.prototype.write = function(chunk, encoding, cb) {
     encoding = null;
   }
 
-  if (chunk instanceof Uint8Array)
+  if (isUint8Array(chunk))
     chunk = new Buffer(chunk);
-  if (chunk instanceof ArrayBuffer)
+  if (isArrayBuffer(chunk))
     chunk = new Buffer(new Uint8Array(chunk));
   
   if (Buffer.isBuffer(chunk))

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



More information about the Pkg-javascript-commits mailing list