Sha256: 92eb2f6b68ea7eb9ea1459e86149e7f0b5d32f0ef0e19964d8a8e32e1e7c2291

Contents?: true

Size: 1.59 KB

Versions: 57

Compression:

Stored size: 1.59 KB

Contents

var test = require('tape')
var toBuffer = require('../')

test('convert to buffer from Uint8Array', function (t) {
  if (typeof Uint8Array !== 'undefined') {
    var arr = new Uint8Array([1, 2, 3])
    arr = toBuffer(arr)

    t.deepEqual(arr, Buffer.from([1, 2, 3]), 'contents equal')
    t.ok(Buffer.isBuffer(arr), 'is buffer')
    t.equal(arr.readUInt8(0), 1)
    t.equal(arr.readUInt8(1), 2)
    t.equal(arr.readUInt8(2), 3)
  } else {
    t.pass('browser lacks Uint8Array support, skip test')
  }
  t.end()
})

test('convert to buffer from another arrayview type (Uint32Array)', function (t) {
  if (typeof Uint32Array !== 'undefined' && Buffer.TYPED_ARRAY_SUPPORT !== false) {
    var arr = new Uint32Array([1, 2, 3])
    arr = toBuffer(arr)

    t.deepEqual(arr, Buffer.from([1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0]), 'contents equal')
    t.ok(Buffer.isBuffer(arr), 'is buffer')
    t.equal(arr.readUInt32LE(0), 1)
    t.equal(arr.readUInt32LE(4), 2)
    t.equal(arr.readUInt32LE(8), 3)
    t.equal(arr instanceof Uint8Array, true)
  } else {
    t.pass('browser lacks Uint32Array support, skip test')
  }
  t.end()
})

test('convert to buffer from ArrayBuffer', function (t) {
  if (typeof Uint32Array !== 'undefined' && Buffer.TYPED_ARRAY_SUPPORT !== false) {
    var arr = new Uint32Array([1, 2, 3]).subarray(1, 2)
    arr = toBuffer(arr)

    t.deepEqual(arr, Buffer.from([2, 0, 0, 0]), 'contents equal')
    t.ok(Buffer.isBuffer(arr), 'is buffer')
    t.equal(arr.readUInt32LE(0), 2)
    t.equal(arr instanceof Uint8Array, true)
  } else {
    t.pass('browser lacks ArrayBuffer support, skip test')
  }
  t.end()
})

Version data entries

57 entries across 57 versions & 2 rubygems

Version Path
immosquare-cleaner-0.1.60 node_modules/typedarray-to-buffer/test/basic.js
immosquare-cleaner-0.1.59 node_modules/typedarray-to-buffer/test/basic.js
immosquare-cleaner-0.1.58 node_modules/typedarray-to-buffer/test/basic.js
immosquare-cleaner-0.1.57 node_modules/typedarray-to-buffer/test/basic.js
immosquare-cleaner-0.1.56 node_modules/typedarray-to-buffer/test/basic.js
immosquare-cleaner-0.1.55 node_modules/typedarray-to-buffer/test/basic.js
immosquare-cleaner-0.1.54 node_modules/typedarray-to-buffer/test/basic.js
immosquare-cleaner-0.1.53 node_modules/typedarray-to-buffer/test/basic.js
immosquare-cleaner-0.1.52 node_modules/typedarray-to-buffer/test/basic.js
trusty-cms-6.3.1 node_modules/typedarray-to-buffer/test/basic.js
immosquare-cleaner-0.1.51 node_modules/typedarray-to-buffer/test/basic.js
immosquare-cleaner-0.1.50 node_modules/typedarray-to-buffer/test/basic.js
immosquare-cleaner-0.1.49 node_modules/typedarray-to-buffer/test/basic.js
immosquare-cleaner-0.1.48 node_modules/typedarray-to-buffer/test/basic.js
immosquare-cleaner-0.1.47 node_modules/typedarray-to-buffer/test/basic.js
immosquare-cleaner-0.1.46 node_modules/typedarray-to-buffer/test/basic.js
immosquare-cleaner-0.1.45 node_modules/typedarray-to-buffer/test/basic.js
immosquare-cleaner-0.1.44 node_modules/typedarray-to-buffer/test/basic.js
immosquare-cleaner-0.1.43 node_modules/typedarray-to-buffer/test/basic.js
immosquare-cleaner-0.1.42 node_modules/typedarray-to-buffer/test/basic.js