return this
}
-/**
- * Creates a new `ArrayBuffer` with the *copied* memory of the buffer instance.
- * Added in Node 0.12. Only available in browsers that support ArrayBuffer.
- */
-Buffer.prototype.toArrayBuffer = function toArrayBuffer () {
- if (typeof Uint8Array !== 'undefined') {
- if (Buffer.TYPED_ARRAY_SUPPORT) {
- return (new Buffer(this)).buffer
- } else {
- var buf = new Uint8Array(this.length)
- for (var i = 0, len = buf.length; i < len; i += 1) {
- buf[i] = this[i]
- }
- return buf.buffer
- }
- } else {
- throw new TypeError('Buffer.toArrayBuffer not supported in this browser')
- }
-}
-
// HELPER FUNCTIONS
// ================
arr.writeDoubleBE = BP.writeDoubleBE
arr.fill = BP.fill
arr.inspect = BP.inspect
- arr.toArrayBuffer = BP.toArrayBuffer
return arr
}
t.equal(B.isBuffer('hey'), false)
t.end()
})
-
-test('Buffer.toArrayBuffer', function (t) {
- var data = [1, 2, 3, 4, 5, 6, 7, 8]
- if (typeof Uint8Array !== 'undefined') {
- var result = new B(data).toArrayBuffer()
- var expected = new Uint8Array(data).buffer
- for (var i = 0; i < expected.byteLength; i++) {
- t.equal(result[i], expected[i])
- }
- } else {
- t.pass('No toArrayBuffer() method provided in old browsers')
- }
- t.end()
-})