this.length = subject > 0 ? subject >>> 0 : 0;
else if (util.isString(subject))
this.length = Buffer.byteLength(subject, encoding = encoding || 'utf8');
- else if (util.isObject(subject))
+ else if (util.isObject(subject)) {
+ if (subject.type === 'Buffer' && util.isArray(subject.data))
+ subject = subject.data;
+
this.length = +subject.length > 0 ? Math.floor(+subject.length) : 0;
- else
+ } else
throw new TypeError('must start with number, buffer, array or string');
if (this.length > kMaxLength) {
}));
})();
+// issue GH-7849
+(function() {
+ var buf = new Buffer('test');
+ var json = JSON.stringify(buf);
+ var obj = JSON.parse(json);
+ var copy = new Buffer(obj);
+
+ assert(buf.equals(copy));
+})();
+
// issue GH-4331
assert.throws(function() {
new Buffer(0xFFFFFFFF);