PHP 8.2.30
Preview: Buffer.js Size: 1.53 KB
/home/byroehnu/.trash/node_modules11/restructure/test/Buffer.js

import assert from 'assert';
import {Buffer as BufferT, uint8, DecodeStream, EncodeStream} from 'restructure';

describe('Buffer', function() {
  describe('decode', function() {
    it('should decode', function() {
      const buffer = new Uint8Array([0xab, 0xff]);
      const buf = new BufferT(2);
      assert.deepEqual(buf.fromBuffer(buffer), new Uint8Array([0xab, 0xff]));
  });

    it('should decode with parent key length', function() {
      const stream = new DecodeStream(new Uint8Array([0xab, 0xff, 0x1f, 0xb6]));
      const buf = new BufferT('len');
      assert.deepEqual(buf.decode(stream, {len: 3}), new Uint8Array([0xab, 0xff, 0x1f]));
      assert.deepEqual(buf.decode(stream, {len: 1}), new Uint8Array([0xb6]));
  });
});

  describe('size', function() {
    it('should return size', function() {
      const buf = new BufferT(2);
      assert.equal(buf.size(new Uint8Array([0xab, 0xff])), 2);
    });

    it('should use defined length if no value given', function() {
      const array = new BufferT(10);
      assert.equal(array.size(), 10);
    });
  });

  describe('encode', function() {
    it('should encode', function() {
      const buf = new BufferT(2);
      const buffer = buf.toBuffer(new Uint8Array([0xab, 0xff]));
      assert.deepEqual(buffer, new Uint8Array([0xab, 0xff]));
    });

    it('should encode length before buffer', function() {
      const buf = new BufferT(uint8);
      const buffer = buf.toBuffer(new Uint8Array([0xab, 0xff]));
      assert.deepEqual(buffer, new Uint8Array([2, 0xab, 0xff]));
    });
  });
});

Directory Contents

Dirs: 0 × Files: 15

Name Size Perms Modified Actions
3.97 KB lrw-r--r-- 2026-02-14 19:19:14
Edit Download
1.04 KB lrw-r--r-- 2026-02-14 19:19:14
Edit Download
1.15 KB lrw-r--r-- 2026-02-14 19:19:16
Edit Download
1.53 KB lrw-r--r-- 2026-02-14 19:19:16
Edit Download
3.53 KB lrw-r--r-- 2026-02-14 19:19:16
Edit Download
3.74 KB lrw-r--r-- 2026-02-14 19:19:16
Edit Download
831 B lrw-r--r-- 2026-02-14 19:19:16
Edit Download
1.87 KB lrw-r--r-- 2026-02-14 19:19:18
Edit Download
11.03 KB lrw-r--r-- 2026-02-14 19:19:18
Edit Download
3.83 KB lrw-r--r-- 2026-02-14 19:19:18
Edit Download
9.48 KB lrw-r--r-- 2026-02-14 19:19:18
Edit Download
820 B lrw-r--r-- 2026-02-14 19:19:18
Edit Download
5.61 KB lrw-r--r-- 2026-02-14 19:19:18
Edit Download
3.45 KB lrw-r--r-- 2026-02-14 19:19:18
Edit Download
11.37 KB lrw-r--r-- 2026-02-14 19:19:18
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).