PHP 8.2.30
Preview: Bitfield.js Size: 741 B
/home/byroehnu/.trash/node_modules11/restructure/src/Bitfield.js

import {Base} from './Base.js';

export class Bitfield extends Base {
  constructor(type, flags = []) {
    super();
    this.type = type;
    this.flags = flags;
  }

  decode(stream) {
    const val = this.type.decode(stream);

    const res = {};
    for (let i = 0; i < this.flags.length; i++) {
      const flag = this.flags[i];
      if (flag != null) {
        res[flag] = !!(val & (1 << i));
      }
    }

    return res;
  }

  size() {
    return this.type.size();
  }

  encode(stream, keys) {
    let val = 0;
    for (let i = 0; i < this.flags.length; i++) {
      const flag = this.flags[i];
      if (flag != null) {
        if (keys[flag]) { val |= (1 << i); }
      }
    }

    return this.type.encode(stream, val);
  }
}

Directory Contents

Dirs: 0 × Files: 17

Name Size Perms Modified Actions
2.43 KB lrw-r--r-- 2026-02-14 19:19:14
Edit Download
412 B lrw-r--r-- 2026-02-14 19:19:14
Edit Download
741 B lrw-r--r-- 2026-02-14 19:19:14
Edit Download
398 B lrw-r--r-- 2026-02-14 19:19:16
Edit Download
795 B lrw-r--r-- 2026-02-14 19:19:16
Edit Download
1.85 KB lrw-r--r-- 2026-02-14 19:19:16
Edit Download
3.13 KB lrw-r--r-- 2026-02-14 19:19:16
Edit Download
533 B lrw-r--r-- 2026-02-14 19:19:16
Edit Download
1.62 KB lrw-r--r-- 2026-02-14 19:19:18
Edit Download
2.23 KB lrw-r--r-- 2026-02-14 19:19:18
Edit Download
920 B lrw-r--r-- 2026-02-14 19:19:18
Edit Download
4.09 KB lrw-r--r-- 2026-02-14 19:19:18
Edit Download
519 B lrw-r--r-- 2026-02-14 19:19:18
Edit Download
3.71 KB lrw-r--r-- 2026-02-14 19:19:18
Edit Download
2.33 KB lrw-r--r-- 2026-02-14 19:19:18
Edit Download
723 B lrw-r--r-- 2026-02-14 19:19:18
Edit Download
3.01 KB lrw-r--r-- 2026-02-14 19:19:18
Edit Download

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