From ba64f07bca61760f0a96f463cb9945fef4cd98e7 Mon Sep 17 00:00:00 2001 From: Kevin Roark Date: Wed, 5 Mar 2014 00:20:52 -0500 Subject: [PATCH] Removed has-binary-data dependency And replaced it with better isBuf function. Has binary data would not have checked objects that contain blobs. isBuf only checks the current object, not its child objects --- binary.js | 15 ++++++++++++--- package.json | 3 +-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/binary.js b/binary.js index f2ec8009..4e966622 100644 --- a/binary.js +++ b/binary.js @@ -3,7 +3,6 @@ */ var isArray = require('isarray'); -var hasBin = require('has-binary-data'); /** * Replaces every Buffer | ArrayBuffer in packet with a numbered placeholder. @@ -127,7 +126,7 @@ exports.removeBlobs = function(data, callback) { for (var i = 0; i < obj.length; i++) { removeBlobsRecursive(obj[i], i, obj); } - } else if (obj && 'object' == typeof obj && !hasBin(obj)) { // and object + } else if (obj && 'object' == typeof obj && !isBuf(obj)) { // and object for (var key in obj) { removeBlobsRecursive(obj[key], key, obj); } @@ -140,4 +139,14 @@ exports.removeBlobs = function(data, callback) { if (!pendingBlobs) { callback(bloblessData); } -} \ No newline at end of file +} + +/** + * Returns true if obj is a buffer or an arraybuffer. + * + * @api private + */ +function isBuf(obj) { + return (global.Buffer && Buffer.isBuffer(obj)) || + (global.ArrayBuffer && obj instanceof ArrayBuffer); +} diff --git a/package.json b/package.json index 204750d8..be012eaf 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,7 @@ "debug": "0.7.4", "json3": "3.2.6", "emitter": "http://github.com/component/emitter/archive/1.0.1.tar.gz", - "isarray": "0.0.1", - "has-binary-data": "0.1.0" + "isarray": "0.0.1" }, "devDependencies": { "mocha": "1.16.2",