| Server IP : 68.183.124.220 / Your IP : 216.73.217.137 Web Server : Apache/2.4.18 (Ubuntu) System : Linux Sandbox-A 4.4.0-210-generic #242-Ubuntu SMP Fri Apr 16 09:57:56 UTC 2021 x86_64 User : gavin ( 1000) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/gavin/workspace/readjs/node_modules/has-binary/ |
Upload File : |
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()));
});
}
});