REDROOM
PHP 8.2.30
Path:
Logout
Edit File
Size: 3.97 KB
Close
/home/byroehnu/.trash/node_modules11/restructure/test/Array.js
Text
Base64
import assert from 'assert'; import {Array as ArrayT, Pointer, uint8, uint16, DecodeStream, EncodeStream} from 'restructure'; describe('Array', function() { describe('decode', function() { it('should decode fixed length', function() { const buffer = new Uint8Array([1, 2, 3, 4, 5]); const array = new ArrayT(uint8, 4); assert.deepEqual(array.fromBuffer(buffer), [1, 2, 3, 4]); }); it('should decode fixed amount of bytes', function() { const buffer = new Uint8Array([1, 2, 3, 4, 5]); const array = new ArrayT(uint16, 4, 'bytes'); assert.deepEqual(array.fromBuffer(buffer), [258, 772]); }); it('should decode length from parent key', function() { const stream = new DecodeStream(new Uint8Array([1, 2, 3, 4, 5])); const array = new ArrayT(uint8, 'len'); assert.deepEqual(array.decode(stream, {len: 4}), [1, 2, 3, 4]); }); it('should decode amount of bytes from parent key', function() { const stream = new DecodeStream(new Uint8Array([1, 2, 3, 4, 5])); const array = new ArrayT(uint16, 'len', 'bytes'); assert.deepEqual(array.decode(stream, {len: 4}), [258, 772]); }); it('should decode length as number before array', function() { const buffer = new Uint8Array([4, 1, 2, 3, 4, 5]); const array = new ArrayT(uint8, uint8); assert.deepEqual(array.fromBuffer(buffer), [1, 2, 3, 4]); }); it('should decode amount of bytes as number before array', function() { const buffer = new Uint8Array([4, 1, 2, 3, 4, 5]); const array = new ArrayT(uint16, uint8, 'bytes'); assert.deepEqual(array.fromBuffer(buffer), [258, 772]); }); it('should decode length from function', function() { const buffer = new Uint8Array([1, 2, 3, 4, 5]); const array = new ArrayT(uint8, function() { return 4; }); assert.deepEqual(array.fromBuffer(buffer), [1, 2, 3, 4]); }); it('should decode amount of bytes from function', function() { const buffer = new Uint8Array([1, 2, 3, 4, 5]); const array = new ArrayT(uint16, (function() { return 4; }), 'bytes'); assert.deepEqual(array.fromBuffer(buffer), [258, 772]); }); it('should decode to the end of the parent if no length is given', function() { const stream = new DecodeStream(new Uint8Array([1, 2, 3, 4, 5])); const array = new ArrayT(uint8); assert.deepEqual(array.decode(stream, {_length: 4, _startOffset: 0}), [1, 2, 3, 4]); }); it('should decode to the end of the stream if no parent and length is given', function() { const buffer = new Uint8Array([1, 2, 3, 4]); const array = new ArrayT(uint8); assert.deepEqual(array.fromBuffer(buffer), [1, 2, 3, 4]); }); }); describe('size', function() { it('should use array length', function() { const array = new ArrayT(uint8, 10); assert.equal(array.size([1, 2, 3, 4]), 4); }); it('should add size of length field before string', function() { const array = new ArrayT(uint8, uint8); assert.equal(array.size([1, 2, 3, 4]), 5); }); it('should use defined length if no value given', function() { const array = new ArrayT(uint8, 10); assert.equal(array.size(), 10); }); }); describe('encode', function() { it('should encode using array length', function() { const array = new ArrayT(uint8, 10); const buffer = array.toBuffer([1, 2, 3, 4]); assert.deepEqual(buffer, new Uint8Array([1, 2, 3, 4])); }); it('should encode length as number before array', function() { const array = new ArrayT(uint8, uint8); const buffer = array.toBuffer([1, 2, 3, 4]); assert.deepEqual(buffer, new Uint8Array([4, 1, 2, 3, 4])); }); it('should add pointers after array if length is encoded at start', function() { const array = new ArrayT(new Pointer(uint8, uint8), uint8); const buffer = array.toBuffer([1, 2, 3, 4]); assert.deepEqual(buffer, new Uint8Array([4, 5, 6, 7, 8, 1, 2, 3, 4])); }); }); });
Save
Close
Exit & Reset
Text mode: syntax highlighting auto-detects file type.
Directory Contents
Dirs: 0 × Files: 15
Delete Selected
Select All
Select None
Sort:
Name
Size
Modified
Enable drag-to-move
Name
Size
Perms
Modified
Actions
Array.js
3.97 KB
lrw-r--r--
2026-02-14 19:19:14
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Bitfield.js
1.04 KB
lrw-r--r--
2026-02-14 19:19:14
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Boolean.js
1.15 KB
lrw-r--r--
2026-02-14 19:19:16
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Buffer.js
1.53 KB
lrw-r--r--
2026-02-14 19:19:16
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
DecodeStream.js
3.53 KB
lrw-r--r--
2026-02-14 19:19:16
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
EncodeStream.js
3.74 KB
lrw-r--r--
2026-02-14 19:19:16
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Enum.js
831 B
lrw-r--r--
2026-02-14 19:19:16
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
LazyArray.js
1.87 KB
lrw-r--r--
2026-02-14 19:19:18
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Number.js
11.03 KB
lrw-r--r--
2026-02-14 19:19:18
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Optional.js
3.83 KB
lrw-r--r--
2026-02-14 19:19:18
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Pointer.js
9.48 KB
lrw-r--r--
2026-02-14 19:19:18
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Reserved.js
820 B
lrw-r--r--
2026-02-14 19:19:18
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
String.js
5.61 KB
lrw-r--r--
2026-02-14 19:19:18
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Struct.js
3.45 KB
lrw-r--r--
2026-02-14 19:19:18
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
VersionedStruct.js
11.37 KB
lrw-r--r--
2026-02-14 19:19:18
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Zip Selected
If ZipArchive is unavailable, a
.tar
will be created (no compression).