pax_global_header00006660000000000000000000000064126232165310014513gustar00rootroot0000000000000052 comment=73875a20978a219f726f7d313ccd1de19335f5a1 has-binary-0.1.7/000077500000000000000000000000001262321653100135555ustar00rootroot00000000000000has-binary-0.1.7/.gitignore000066400000000000000000000001411262321653100155410ustar00rootroot00000000000000lib-cov *.seed *.log *.csv *.dat *.out *.pid *.gz pids logs results npm-debug.log node_modules has-binary-0.1.7/History.md000066400000000000000000000006131262321653100155400ustar00rootroot00000000000000 0.1.7 / 2015-11-18 ================== * fix toJSON [@jderuere] * fix `global.isBuffer` usage [@tonetheman] * fix tests on modern versions of node * bump mocha 0.1.6 / 2015-01-24 ================== * fix "undefined function" bug when iterating an object created with Object.create(null) [gunta] 0.1.5 / 2014-09-04 ================== * prevent browserify from bundling `Buffer` has-binary-0.1.7/LICENSE000066400000000000000000000020661262321653100145660ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2014 Kevin Roark Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. has-binary-0.1.7/Makefile000066400000000000000000000000531262321653100152130ustar00rootroot00000000000000 test: @./node_modules/.bin/mocha test.js has-binary-0.1.7/README.md000066400000000000000000000001351262321653100150330ustar00rootroot00000000000000has-binarydata.js ================= Simple module to test if an object contains binary data has-binary-0.1.7/index.js000066400000000000000000000022671262321653100152310ustar00rootroot00000000000000 /* * Module requirements. */ var isArray = require('isarray'); /** * Module exports. */ module.exports = hasBinary; /** * Checks for binary data. * * Right now only Buffer and ArrayBuffer are supported.. * * @param {Object} anything * @api public */ function hasBinary(data) { function _hasBinary(obj) { if (!obj) return false; if ( (global.Buffer && global.Buffer.isBuffer && global.Buffer.isBuffer(obj)) || (global.ArrayBuffer && obj instanceof ArrayBuffer) || (global.Blob && obj instanceof Blob) || (global.File && obj instanceof File) ) { return true; } if (isArray(obj)) { for (var i = 0; i < obj.length; i++) { if (_hasBinary(obj[i])) { return true; } } } else if (obj && 'object' == typeof obj) { // see: https://github.com/Automattic/has-binary/pull/4 if (obj.toJSON && 'function' == typeof obj.toJSON) { obj = obj.toJSON(); } for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key) && _hasBinary(obj[key])) { return true; } } } return false; } return _hasBinary(data); } has-binary-0.1.7/package.json000066400000000000000000000005271262321653100160470ustar00rootroot00000000000000{ "name": "has-binary", "version": "0.1.7", "description": "A function that takes anything in javascript and returns true if its argument contains binary data.", "dependencies": { "isarray": "0.0.1" }, "devDependencies": { "better-assert": "1.0.0", "mocha": "2.3.4" }, "author": "Kevin Roark", "license": "MIT" } has-binary-0.1.7/test.js000066400000000000000000000035171262321653100151000ustar00rootroot00000000000000 var hasBinary = require('./'); var assert = require('better-assert'); var fs = require('fs'); describe('has-binarydata', function(){ it('should work with buffer', function(){ assert(hasBinary(fs.readFileSync('./test.js'))); }); it('should work with an array that does not contain binary', function() { var arr = [1, 'cool', 2]; assert(!hasBinary(arr)); }); it('should work with an array that contains a buffer', function() { var arr = [1, new Buffer('asdfasdf', 'utf8'), 2]; assert(hasBinary(arr)); }); it('should work with an object that does not contain binary', function() { var ob = {a: 'a', b: [], c: 1234, toJSON: '{\"a\": \"a\"}'}; assert(!hasBinary(ob)); }); it('should work with an object that contains a buffer', function() { var ob = {a: 'a', b: new Buffer('abc'), c: 1234, toJSON: '{\"a\": \"a\"}'}; assert(hasBinary(ob)); }); it('should work with null', function() { assert(!hasBinary(null)); }); it('should work with undefined', function() { assert(!hasBinary(undefined)); }); it('should work with a complex object that contains undefined and no binary', function() { var ob = { x: ['a', 'b', 123], y: undefined, z: {a: 'x', b: 'y', c: 3, d: null}, w: [] }; assert(!hasBinary(ob)); }); it('should work with a complex object that contains undefined and binary', function() { var ob = { x: ['a', 'b', 123], y: undefined, z: {a: 'x', b: 'y', c: 3, d: null}, w: [], bin: new Buffer('xxx') }; assert(hasBinary(ob)); }); if (global.ArrayBuffer) { it('should work with an ArrayBuffer', function() { assert(hasBinary(new ArrayBuffer())); }); } if (global.Blob) { it('should work with a Blob', function() { assert(hasBinary(new Blob())); }); } });