PHP 8.2.30
Preview: Number.js Size: 2.23 KB
/home/byroehnu/.trash/node_modules11/restructure/src/Number.js

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

class NumberT extends Base {
  constructor(type, endian = 'BE') {
    super();
    this.type = type;
    this.endian = endian;
    this.fn = this.type;
    if (this.type[this.type.length - 1] !== '8') {
      this.fn += this.endian;
    }
  }

  size() {
    return DecodeStream.TYPES[this.type];
  }

  decode(stream) {
    return stream[`read${this.fn}`]();
  }

  encode(stream, val) {
    return stream[`write${this.fn}`](val);
  }
}

export {NumberT as Number};

export const uint8 = new NumberT('UInt8');
export const uint16be = new NumberT('UInt16', 'BE');
export const uint16 = uint16be;
export const uint16le = new NumberT('UInt16', 'LE');
export const uint24be = new NumberT('UInt24', 'BE');
export const uint24 = uint24be;
export const uint24le = new NumberT('UInt24', 'LE');
export const uint32be = new NumberT('UInt32', 'BE');
export const uint32 = uint32be;
export const uint32le = new NumberT('UInt32', 'LE');
export const int8 = new NumberT('Int8');
export const int16be = new NumberT('Int16', 'BE');
export const int16 = int16be;
export const int16le = new NumberT('Int16', 'LE');
export const int24be = new NumberT('Int24', 'BE');
export const int24 = int24be;
export const int24le = new NumberT('Int24', 'LE');
export const int32be = new NumberT('Int32', 'BE');
export const int32 = int32be;
export const int32le = new NumberT('Int32', 'LE');
export const floatbe = new NumberT('Float', 'BE');
export const float = floatbe;
export const floatle = new NumberT('Float', 'LE');
export const doublebe = new NumberT('Double', 'BE');
export const double = doublebe;
export const doublele = new NumberT('Double', 'LE');

export class Fixed extends NumberT {
  constructor(size, endian, fracBits = size >> 1) {
    super(`Int${size}`, endian);
    this._point = 1 << fracBits;
  }

  decode(stream) {
    return super.decode(stream) / this._point;
  }

  encode(stream, val) {
    return super.encode(stream, (val * this._point) | 0);
  }
}

export const fixed16be = new Fixed(16, 'BE');
export const fixed16 = fixed16be;
export const fixed16le = new Fixed(16, 'LE');
export const fixed32be = new Fixed(32, 'BE');
export const fixed32 = fixed32be;
export const fixed32le = new Fixed(32, 'LE');

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).