Buffer.isEncoding = function(encoding) { return Buffer.isNativeEncoding(encoding) || iconv.encodingExists(encoding); }
throws(() => Buffer.from(input),
state.getBuffer().forEach(function(el) { if (el.chunk instanceof Buffer) bytes += el.chunk.length; else bytes += Buffer.byteLength(el.chunk, el.encoding); });
isBuffer: function isBuffer(arg) { return buffer.Buffer.isBuffer(arg) || arg instanceof Uint8Array; },
Server.prototype._setServerData = function(data) { this.setTicketKeys(Buffer.from(data.ticketKeys, 'hex')); };
Transaction.prototype.fromString = function(string) { this.fromBuffer(buffer.Buffer.from(string, 'hex')); };
} }; OutgoingMessage.prototype._implicitHeader = function _implicitHeader() { throw new Error('_implicitHeader() method is not implemented'); }; Object.defineProperty(OutgoingMessage.prototype, 'headersSent', { configurable: true, enumerable: true, get: function() { return !!this._header; } }); const crlf_buf = Buffer.from('\r\n'); OutgoingMessage.prototype.write = function write(chunk, encoding, callback) { if (this.finished) { var err = new Error('write after end'); process.nextTick(writeAfterEndNT, this, err, callback); return true; } if (!this._header) { this._implicitHeader(); } if (!this._hasBody) { debug('This type of response MUST NOT have a body. ' + 'Ignoring write() calls.');
}).register('foo', function foo(req, res, arg2, arg3) { assert.ok(Buffer.isBuffer(arg2), 'handler got an arg2 buffer'); assert.ok(Buffer.isBuffer(arg3), 'handler got an arg3 buffer'); res.headers.as = 'raw'; res.sendOk(arg2, arg3); });
Crypt.prototype.encrypt = function (data, iv, f) { "use strict"; var key, ekey, iv64, cipher, jdata, edata = []; try { if (!f) { f = iv; iv = null; } if (this.key.is_public) { key = crypto.randomBytes(Crypt._AES_128_KEY_SIZE); ekey = crypto.publicEncrypt( { key: this.key.key, padding: crypto.constants.RSA_PKCS1_OAEP_PADDING }, key); if (this.encoding) { ekey = ekey.toString(this.encoding); } } else if (!this.key.is_private) { key = this.key.key || this.key; } else { throw new Error("can't encrypt using private key"); } iv = iv || crypto.randomBytes(Crypt._AES_BLOCK_SIZE); if (typeof iv === 'string') { iv = new Buffer(iv, 'binary'); } iv64 = this.encoding ? iv.toString(this.encoding) : iv; cipher = crypto.createCipheriv('AES-128-CBC', key, iv); cipher.setAutoPadding(this.options.pad); jdata = this.stringify(data); if (this.options.check) { edata.push(cipher.update(crypto.createHash('sha256') .update(jdata, 'binary') .digest(), undefined, this.encoding)); } edata.push(cipher.update(jdata, 'binary', this.encoding)); edata.push(cipher.final(this.encoding)); if (this.encoding) { edata = edata.join(''); } else { edata = Buffer.concat(edata); } } catch (ex) { return f.call(this, Crypt._ensure_error(ex)); } f.call(this, null, { iv: iv64, data: edata, ekey: ekey, version: Crypt.get_version() }); };
.pipe(map(function (file, cb) { file.contents = buffer.Buffer.concat([header, file.contents]); cb(null, file); }))
'use strict'; require('../common'); const assert = require('assert'); const Buffer = require('buffer').Buffer; const b = Buffer.from('abcdef'); const buf_a = Buffer.from('a'); const buf_bc = Buffer.from('bc'); const buf_f = Buffer.from('f'); const buf_z = Buffer.from('z'); const buf_empty = Buffer.from(''); assert(b.includes('a')); assert(!b.includes('a', 1)); assert(!b.includes('a', -1)); assert(!b.includes('a', -4)); assert(b.includes('a', -b.length)); assert(b.includes('a', NaN)); assert(b.includes('a', -Infinity)); assert(!b.includes('a', Infinity)); assert(b.includes('bc')); assert(!b.includes('bc', 2)); assert(!b.includes('bc', -1)); assert(!b.includes('bc', -3)); assert(b.includes('bc', -5)); assert(b.includes('bc', NaN)); assert(b.includes('bc', -Infinity)); assert(!b.includes('bc', Infinity)); assert(b.includes('f'), b.length - 1); assert(!b.includes('z'));
return promise.then(function (result) { if (Buffer.isBuffer(result)) { result = result.toString(); } return transformator(result, jobQueue); });
assert.throws(function () { b.unpack('N', 8); });
require("../common"); assert = require("assert"); var Buffer = require('buffer').Buffer; var b = new Buffer(1024); console.log("b.length == " + b.length); assert.strictEqual(1024, b.length); for (var i = 0; i < 1024; i++) { assert.ok(b[i] >= 0); b[i] = i % 256; } for (var i = 0; i < 1024; i++) { assert.equal(i % 256, b[i]); } var c = new Buffer(512); // copy 512 bytes, from 0 to 512. var copied = b.copy(c, 0, 0, 512); console.log("copied " + copied + " bytes from b into c"); assert.strictEqual(512, copied); for (var i = 0; i < c.length; i++) { print('.'); assert.equal(i % 256, c[i]); } console.log("");
SerialPort.prototype.write = function (b) { if (Buffer.isBuffer(b)) serialport_native.write(this.fd, b); else serialport_native.write(this.fd, new Buffer(b)); };
Crypt.prototype.decrypt = function (data, f) { "use strict"; var key, decipher, ddata, jdata; try { Crypt.check_version(data); if (this.key.is_private) { key = crypto.privateDecrypt( { key: this.key.key, padding: crypto.constants.RSA_PKCS1_OAEP_PADDING }, this.encoding ? new Buffer(data.ekey, this.encoding) : data.ekey); } else if (!this.key.is_public) { key = this.key.key || this.key; } else { throw new Error("can't decrypt using public key"); } decipher = crypto.createDecipheriv( 'AES-128-CBC', key, this.encoding ? new Buffer(data.iv, this.encoding) : data.iv); decipher.setAutoPadding(this.options.pad); ddata = decipher.update(data.data, this.encoding); ddata = Buffer.concat([ddata, decipher.final()]); if (this.options.check) { jdata = ddata.slice(Crypt._SHA256_SIZE); if (!Crypt._buffer_equal(crypto.createHash('sha256') .update(jdata) .digest(), ddata.slice(0, Crypt._SHA256_SIZE))) { throw new Error('digest mismatch'); } } else { jdata = ddata; } jdata = this.parse(jdata); } catch (ex) { return f.call(this, Crypt._ensure_error(ex)); } f.call(this, null, jdata); };
function t(t,h){h?(c[0]=c[16]=c[1]=c[2]=c[3]=c[4]=c[5]=c[6]=c[7]=c[8]=c[9]=c[10]=c[11]=c[12]=c[13]=c[14]=c[15]=0,this.blocks=c):this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t?(this.h0=3238371032,this.h1=914150663,this.h2=812702999,this.h3=4144912697,this.h4=4290775857,this.h5=1750603025,this.h6=1694076839,this.h7=3204075428):(this.h0=1779033703,this.h1=3144134277,this.h2=1013904242,this.h3=2773480762,this.h4=1359893119,this.h5=2600822924,this.h6=528734635,this.h7=1541459225),this.block=this.start=this.bytes=0,this.finalized=this.hashed=!1,this.first=!0,this.is224=t}var h="object"==typeof window?window:{},i=!h.JS_SHA256_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node;i&&(h=global);var s=!h.JS_SHA256_NO_COMMON_JS&&"object"==typeof module&&module.exports,e="function"==typeof define&&define.amd,r="undefined"!=typeof ArrayBuffer,n="0123456789abcdef".split(""),o=[-2147483648,8388608,32768,128],a=[24,16,8,0],f=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],u=["hex","array","digest","arrayBuffer"],c=[],p=function(h,i){return function(s){return new t(i,!0).update(s)[h]()}},d=function(h){var s=p("hex",h);i&&(s=y(s,h)),s.create=function(){return new t(h)},s.update=function(t){return s.create().update(t)};for(var e=0;e<u.length;++e){var r=u[e];s[r]=p(r,h)}return s},y=function(t,h){var i=require("crypto"),s=require("buffer").Buffer,e=h?"sha224":"sha256",n=function(h){if("string"==typeof h)return i.createHash(e).update(h,"utf8").digest("hex");if(r&&h instanceof ArrayBuffer)h=new Uint8Array(h);else if(void 0===h.length)return t(h);return i.createHash(e).update(new s(h)).digest("hex")};return n};t.prototype.update=function(t){if(!this.finalized){var i="string"!=typeof t;i&&r&&t instanceof h.ArrayBuffer&&(t=new Uint8Array(t));for(var s,e,n=0,o=t.length||0,f=this.blocks;o>n;){if(this.hashed&&(this.hashed=!1,f[0]=this.block,f[16]=f[1]=f[2]=f[3]=f[4]=f[5]=f[6]=f[7]=f[8]=f[9]=f[10]=f[11]=f[12]=f[13]=f[14]=f[15]=0),i)for(e=this.start;o>n&&64>e;++n)f[e>>2]|=t[n]<<a[3&e++];else for(e=this.start;o>n&&64>e;++n)s=t.charCodeAt(n),128>s?f[e>>2]|=s<<a[3&e++]:2048>s?(f[e>>2]|=(192|s>>6)<<a[3&e++],f[e>>2]|=(128|63&s)<<a[3&e++]):55296>s||s>=57344?(f[e>>2]|=(224|s>>12)<<a[3&e++],f[e>>2]|=(128|s>>6&63)<<a[3&e++],f[e>>2]|=(128|63&s)<<a[3&e++]):(s=65536+((1023&s)<<10|1023&t.charCodeAt(++n)),f[e>>2]|=(240|s>>18)<<a[3&e++],f[e>>2]|=(128|s>>12&63)<<a[3&e++],f[e>>2]|=(128|s>>6&63)<<a[3&e++],f[e>>2]|=(128|63&s)<<a[3&e++]);this.lastByteIndex=e,this.bytes+=e-this.start,e>=64?(this.block=f[16],this.start=e-64,this.hash(),this.hashed=!0):this.start=e}return this}},t.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,h=this.lastByteIndex;t[16]=this.block,t[h>>2]|=o[3&h],this.block=t[16],h>=56&&(this.hashed||this.hash(),t[0]=this.block,t[16]=t[1]=t[2]=t[3]=t[4]=t[5]=t[6]=t[7]=t[8]=t[9]=t[10]=t[11]=t[12]=t[13]=t[14]=t[15]=0),t[15]=this.bytes<<3,this.hash()}},t.prototype.hash=function(){var t,h,i,s,e,r,n,o,a,u,c,p=this.h0,d=this.h1,y=this.h2,l=this.h3,b=this.h4,v=this.h5,g=this.h6,w=this.h7,k=this.blocks;for(t=16;64>t;++t)e=k[t-15],h=(e>>>7|e<<25)^(e>>>18|e<<14)^e>>>3,e=k[t-2],i=(e>>>17|e<<15)^(e>>>19|e<<13)^e>>>10,k[t]=k[t-16]+h+k[t-7]+i<<0;for(c=d&y,t=0;64>t;t+=4)this.first?(this.is224?(o=300032,e=k[0]-1413257819,w=e-150054599<<0,l=e+24177077<<0):(o=704751109,e=k[0]-210244248,w=e-1521486534<<0,l=e+143694565<<0),this.first=!1):(h=(p>>>2|p<<30)^(p>>>13|p<<19)^(p>>>22|p<<10),i=(b>>>6|b<<26)^(b>>>11|b<<21)^(b>>>25|b<<7),o=p&d,s=o^p&y^c,n=b&v^~b&g,e=w+i+n+f[t]+k[t],r=h+s,w=l+e<<0,l=e+r<<0),h=(l>>>2|l<<30)^(l>>>13|l<<19)^(l>>>22|l<<10),i=(w>>>6|w<<26)^(w>>>11|w<<21)^(w>>>25|w<<7),a=l&p,s=a^l&d^o,n=w&b^~w&v,e=g+i+n+f[t+1]+k[t+1],r=h+s,g=y+e<<0,y=e+r<<0,h=(y>>>2|y<<30)^(y>>>13|y<<19)^(y>>>22|y<<10),i=(g>>>6|g<<26)^(g>>>11|g<<21)^(g>>>25|g<<7),u=y&l,s=u^y&p^a,n=g&w^~g&b,e=v+i+n+f[t+2]+k[t+2],r=h+s,v=d+e<<0,d=e+r<<0,h=(d>>>2|d<<30)^(d>>>13|d<<19)^(d>>>22|d<<10),i=(v>>>6|v<<26)^(v>>>11|v<<21)^(v>>>25|v<<7),c=d&y,s=c^d&l^u,n=v&g^~v&w,e=b+i+n+f[t+3]+k[t+3],r=h+s,b=p+e<<0,p=e+r<<0;this.h0=this.h0+p<<0,this.h1=this.h1+d<<0,this.h2=this.h2+y<<0,this.h3=this.h3+l<<0,this.h4=this.h4+b<<0,this.h5=this.h5+v<<0,this.h6=this.h6+g<<0,this.h7=this.h7+w<<0},t.prototype.hex=function(){this.finalize();var t=this.h0,h=this.h1,i=this.h2,s=this.h3,e=this.h4,r=this.h5,o=this.h6,a=this.h7,f=n[t>>28&15]+n[t>>24&15]+n[t>>20&15]+n[t>>16&15]+n[t>>12&15]+n[t>>8&15]+n[t>>4&15]+n[15&t]+n[h>>28&15]+n[h>>24&15]+n[h>>20&15]+n[h>>16&15]+n[h>>12&15]+n[h>>8&15]+n[h>>4&15]+n[15&h]+n[i>>28&15]+n[i>>24&15]+n[i>>20&15]+n[i>>16&15]+n[i>>12&15]+n[i>>8&15]+n[i>>4&15]+n[15&i]+n[s>>28&15]+n[s>>24&15]+n[s>>20&15]+n[s>>16&15]+n[s>>12&15]+n[s>>8&15]+n[s>>4&15]+n[15&s]+n[e>>28&15]+n[e>>24&15]+n[e>>20&15]+n[e>>16&15]+n[e>>12&15]+n[e>>8&15]+n[e>>4&15]+n[15&e]+n[r>>28&15]+n[r>>24&15]+n[r>>20&15]+n[r>>16&15]+n[r>>12&15]+n[r>>8&15]+n[r>>4&15]+n[15&r]+n[o>>28&15]+n[o>>24&15]+n[o>>20&15]+n[o>>16&15]+n[o>>12&15]+n[o>>8&15]+n[o>>4&15]+n[15&o];return this.is224||(f+=n[a>>28&15]+n[a>>24&15]+n[a>>20&15]+n[a>>16&15]+n[a>>12&15]+n[a>>8&15]+n[a>>4&15]+n[15&a]),f},t.prototype.toString=t.prototype.hex,t.prototype.digest=function(){this.finalize();var t=this.h0,h=this.h1,i=this.h2,s=this.h3,e=this.h4,r=this.h5,n=this.h6,o=this.h7,a=[t>>24&255,t>>16&255,t>>8&255,255&t,h>>24&255,h>>16&255,h>>8&255,255&h,i>>24&255,i>>16&255,i>>8&255,255&i,s>>24&255,s>>16&255,s>>8&255,255&s,e>>24&255,e>>16&255,e>>8&255,255&e,r>>24&255,r>>16&255,r>>8&255,255&r,n>>24&255,n>>16&255,n>>8&255,255&n];return this.is224||a.push(o>>24&255,o>>16&255,o>>8&255,255&o),a},t.prototype.array=t.prototype.digest,t.prototype.arrayBuffer=function(){this.finalize();var t=new ArrayBuffer(this.is224?28:32),h=new DataView(t);return h.setUint32(0,this.h0),h.setUint32(4,this.h1),h.setUint32(8,this.h2),h.setUint32(12,this.h3),h.setUint32(16,this.h4),h.setUint32(20,this.h5),h.setUint32(24,this.h6),this.is224||h.setUint32(28,this.h7),t};var l=d();l.sha256=l,l.sha224=d(!0),s?module.exports=l:(h.sha256=l.sha256,h.sha224=l.sha224,e&&define(function(){return l}))
SlowCrypt._sha256 = function (bufs) { var Buffer = require('buffer').Buffer; return Buffer.from(rstr_sha256(Buffer.concat(bufs).toString('binary')), 'binary'); };
'use strict'; const common = require('../common'); const assert = require('assert'); const path = require('path'); const Buffer = require('buffer').Buffer; const fs = require('fs'); const filename = path.join(common.tmpDir, 'write.txt'); const expected = Buffer.from('hello'); let openCalled = 0; let writeCalled = 0; common.refreshTmpDir(); fs.open(filename, 'w', 0o644, function(err, fd) { openCalled++; if (err) throw err; fs.write(fd, expected, 0, expected.length, null, function(err, written) { writeCalled++; if (err) throw err; assert.equal(expected.length, written); fs.closeSync(fd); var found = fs.readFileSync(filename, 'utf8'); assert.deepEqual(expected.toString(), found); fs.unlinkSync(filename); }); });
test('decoder.write - two byte char', function (t) { var buffer = new Buffer('¢'); t.deepEqual('', decoder.write(buffer.slice(0, 1))); t.deepEqual('¢', decoder.write(buffer.slice(1, 2))); t.end(); });
OutgoingMessage.prototype.end = function end(data, encoding, callback) { if (typeof data === 'function') { callback = data; data = null; } else if (typeof encoding === 'function') { callback = encoding; encoding = null; } if (data && typeof data !== 'string' && !(data instanceof Buffer)) { throw new TypeError('First argument must be a string or Buffer'); } if (this.finished) { return false; } if (!this._header) { if (data) { if (typeof data === 'string') this._contentLength = Buffer.byteLength(data, encoding); else this._contentLength = data.length; } else { this._contentLength = 0; } this._implicitHeader(); } if (data && !this._hasBody) { debug('This type of response MUST NOT have a body. ' + 'Ignoring data passed to end().'); data = null; } if (this.connection && data) this.connection.cork(); if (data) { // Normal body write. this.write(data, encoding); } if (typeof callback === 'function') this.once('finish', callback); var finish = onFinish.bind(undefined, this); var ret; if (this._hasBody && this.chunkedEncoding) { ret = this._send('0\r\n' + this._trailer + '\r\n', 'latin1', finish); } else { // Force a flush, HACK. ret = this._send('', 'latin1', finish); } if (this.connection && data) this.connection.uncork(); this.finished = true; // There is the first message on the outgoing queue, and we've sent // everything to the socket. debug('outgoing message end.'); if (this.output.length === 0 && this.connection && this.connection._httpMessage === this) { this._finish(); } return ret; };
app.get('/', function(request, response) { buffer = fs.readFileSync('index.html'); response.send(buffer.toString()); });
TLSSocket.prototype.setSession = function(session) { if (typeof session === 'string') session = Buffer.from(session, 'latin1'); this._handle.setSession(session); };
Connection.prototype._sendBody = function (channel, body, properties) { // Handles 3 cases // - body is utf8 string // - body is instance of Buffer // - body is an object and its JSON representation is sent // Does not handle the case for streaming bodies. if (typeof(body) == 'string') { var length = Buffer.byteLength(body); //debug('send message length ' + length); sendHeader(this, channel, length, properties); //debug('header sent'); var b = new Buffer(7+length+1); b.used = 0; b[b.used++] = 3; // constants.frameBody serializeInt(b, 2, channel); serializeInt(b, 4, length); b.write(body, b.used, 'utf8'); b.used += length; b[b.used++] = 206; // constants.frameEnd; return this.write(b); //debug('body sent: ' + JSON.stringify(b)); } else if (body instanceof Buffer) { sendHeader(this, channel, body.length, properties); var b = new Buffer(7); b.used = 0; b[b.used++] = 3; // constants.frameBody serializeInt(b, 2, channel); serializeInt(b, 4, body.length); this.write(b); this.write(body); return this.write(new Buffer([206])); // frameEnd } else { var jsonBody = JSON.stringify(body); var length = Buffer.byteLength(jsonBody); debug('sending json: ' + jsonBody); properties = mixin({contentType: 'text/json' }, properties); sendHeader(this, channel, length, properties); var b = new Buffer(7+length+1); b.used = 0; b[b.used++] = 3; // constants.frameBody serializeInt(b, 2, channel); serializeInt(b, 4, length); b.write(jsonBody, b.used, 'utf8'); b.used += length; b[b.used++] = 206; // constants.frameEnd; return this.write(b); } };
'use strict'; require('../common'); const { deepStrictEqual, throws } = require('assert'); const { Buffer } = require('buffer'); const { runInNewContext } = require('vm'); const checkString = 'test'; const check = Buffer.from(checkString); class MyString extends String { constructor() { super(checkString); } } class MyPrimitive { [Symbol.toPrimitive]() { return checkString; } } class MyBadPrimitive { [Symbol.toPrimitive]() { return 1; } } deepStrictEqual(Buffer.from(new String(checkString)), check); deepStrictEqual(Buffer.from(new MyString()), check);
SlabBuffer.prototype.create = function create() { this.isFull = false; this.pool = Buffer.allocUnsafe(tls.SLAB_BUFFER_SIZE); this.offset = 0; this.remaining = this.pool.length; };
function Script(opcodes) { this.opcodes = opcodes || Buffer.alloc(0); }
app.get('/', function(request, response) { response.send(index_buffer.toString('utf8')); });
'use strict'; var common = require('../common'); var assert = require('assert'); var Buffer = require('buffer').Buffer; var SlowBuffer = require('buffer').SlowBuffer; // counter to ensure unique value is always copied var cntr = 0; var b = Buffer.alloc(1024); console.log('b.length == %d', b.length); assert.strictEqual(1024, b.length); b[0] = -1; assert.strictEqual(b[0], 255); for (let i = 0; i < 1024; i++) { b[i] = i % 256; } for (let i = 0; i < 1024; i++) { assert.strictEqual(i % 256, b[i]); } var c = Buffer.alloc(512); console.log('c.length == %d', c.length); assert.strictEqual(512, c.length); var d = Buffer.from([]);
function onResults(err, results) { assert.ifError(err); var errorCall = results.errorCall; assert.equal(errorCall.err, null); assert.ok(Buffer.isBuffer(errorCall.head)); assert.equal(String(errorCall.head), ''); assert.ok(Buffer.isBuffer(errorCall.body)); assert.equal(String(errorCall.body), 'abc'); var errorFrameCall = results.errorFrameCall; var frameErr = errorFrameCall.err; assert.equal(frameErr.type, 'tchannel.busy'); assert.equal(frameErr.isErrorFrame, true); assert.equal(frameErr.errorCode, 3); assert.equal(typeof frameErr.originalId, 'number'); assert.equal(frameErr.message, 'some message'); assert.equal(errorFrameCall.head || null, null); assert.equal(errorFrameCall.body || null, null); var bufferHead = results.bufferHead; assert.equal(bufferHead.err, null); assert.ok(Buffer.isBuffer(bufferHead.head)); assert.equal(String(bufferHead.head), 'abc'); assert.ok(Buffer.isBuffer(bufferHead.body)); assert.equal(String(bufferHead.body), ''); var stringHead = results.stringHead; assert.equal(stringHead.err, null); assert.ok(Buffer.isBuffer(stringHead.head)); assert.equal(String(stringHead.head), 'abc'); assert.ok(Buffer.isBuffer(stringHead.body)); assert.equal(String(stringHead.body), ''); var objectHead = results.objectHead; assert.equal(objectHead.err, null); assert.ok(Buffer.isBuffer(objectHead.head)); assert.equal(String(objectHead.head), '{"value":"abc"}'); assert.ok(Buffer.isBuffer(objectHead.body)); assert.equal(String(objectHead.body), ''); var nullHead = results.nullHead; assert.equal(nullHead.err, null); assert.ok(Buffer.isBuffer(nullHead.head)); assert.equal(String(nullHead.head), ''); assert.ok(Buffer.isBuffer(nullHead.body)); assert.equal(String(nullHead.body), ''); var undefHead = results.undefHead; assert.equal(undefHead.err, null); assert.ok(Buffer.isBuffer(undefHead.head)); assert.equal(String(undefHead.head), ''); assert.ok(Buffer.isBuffer(undefHead.body)); assert.equal(String(undefHead.body), ''); var bufferBody = results.bufferBody; assert.equal(bufferBody.err, null); assert.ok(Buffer.isBuffer(bufferBody.head)); assert.equal(String(bufferBody.head), ''); assert.ok(Buffer.isBuffer(bufferBody.body)); assert.equal(String(bufferBody.body), 'abc'); var stringBody = results.stringBody; assert.equal(stringBody.err, null); assert.ok(Buffer.isBuffer(stringBody.head)); assert.equal(String(stringBody.head), ''); assert.ok(Buffer.isBuffer(stringBody.body)); assert.equal(String(stringBody.body), 'abc'); var objectBody = results.objectBody; assert.equal(objectBody.err, null); assert.ok(Buffer.isBuffer(objectBody.head)); assert.equal(String(objectBody.head), ''); assert.ok(Buffer.isBuffer(objectBody.body)); assert.equal(String(objectBody.body), '{"value":"abc"}'); var nullBody = results.nullBody; assert.equal(nullBody.err, null); assert.ok(Buffer.isBuffer(nullBody.head)); assert.equal(String(nullBody.head), ''); assert.ok(Buffer.isBuffer(nullBody.body)); assert.equal(String(nullBody.body), ''); var undefBody = results.undefBody; assert.equal(undefBody.err, null); assert.ok(Buffer.isBuffer(undefBody.head)); assert.equal(String(undefBody.head), ''); assert.ok(Buffer.isBuffer(undefBody.body)); assert.equal(String(undefBody.body), ''); assert.end(); }