PHP 8.2.30
Preview: DecodeStream.js Size: 1.85 KB
/home/byroehnu/easepaybiz.easetack.com/node_modules/restructure/src/DecodeStream.js

// Node back-compat.
const ENCODING_MAPPING = {
  utf16le: 'utf-16le',
  ucs2: 'utf-16le',
  utf16be: 'utf-16be'
}

export class DecodeStream {
  constructor(buffer) {
    this.buffer = buffer;
    this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
    this.pos = 0;
    this.length = this.buffer.length;
  }

  readString(length, encoding = 'ascii') {
    encoding = ENCODING_MAPPING[encoding] || encoding;

    let buf = this.readBuffer(length);
    try {
      let decoder = new TextDecoder(encoding);
      return decoder.decode(buf);
    } catch (err) {
      return buf;
    }
  }

  readBuffer(length) {
    return this.buffer.slice(this.pos, (this.pos += length));
  }

  readUInt24BE() {
    return (this.readUInt16BE() << 8) + this.readUInt8();
  }

  readUInt24LE() {
    return this.readUInt16LE() + (this.readUInt8() << 16);
  }

  readInt24BE() {
    return (this.readInt16BE() << 8) + this.readUInt8();
  }

  readInt24LE() {
    return this.readUInt16LE() + (this.readInt8() << 16);
  }
}

DecodeStream.TYPES = {
  UInt8: 1,
  UInt16: 2,
  UInt24: 3,
  UInt32: 4,
  Int8: 1,
  Int16: 2,
  Int24: 3,
  Int32: 4,
  Float: 4,
  Double: 8
};

for (let key of Object.getOwnPropertyNames(DataView.prototype)) {
  if (key.slice(0, 3) === 'get') {
    let type = key.slice(3).replace('Ui', 'UI');
    if (type === 'Float32') {
      type = 'Float';
    } else if (type === 'Float64') {
      type = 'Double';
    }
    let bytes = DecodeStream.TYPES[type];
    DecodeStream.prototype['read' + type + (bytes === 1 ? '' : 'BE')] = function () {
      const ret = this.view[key](this.pos, false);
      this.pos += bytes;
      return ret;
    };

    if (bytes !== 1) {
      DecodeStream.prototype['read' + type + 'LE'] = function () {
        const ret = this.view[key](this.pos, true);
        this.pos += bytes;
        return ret;
      };
    }
  }
}

Directory Contents

Dirs: 0 × Files: 18

Name Size Perms Modified Actions
127 B lr--r--r-- 2026-03-14 01:49:07
Edit Download
2.43 KB lrw-r--r-- 2026-03-05 00:19:58
Edit Download
412 B lrw-r--r-- 2026-03-05 00:19:59
Edit Download
741 B lrw-r--r-- 2026-03-05 00:19:59
Edit Download
398 B lrw-r--r-- 2026-03-05 00:20:01
Edit Download
795 B lrw-r--r-- 2026-03-05 00:20:02
Edit Download
1.85 KB lrw-r--r-- 2026-03-05 00:20:03
Edit Download
3.13 KB lrw-r--r-- 2026-03-05 00:20:04
Edit Download
533 B lrw-r--r-- 2026-03-05 00:20:05
Edit Download
1.62 KB lrw-r--r-- 2026-03-05 00:20:07
Edit Download
2.23 KB lrw-r--r-- 2026-03-05 00:20:08
Edit Download
920 B lrw-r--r-- 2026-03-05 00:20:09
Edit Download
4.09 KB lrw-r--r-- 2026-03-05 00:20:09
Edit Download
519 B lrw-r--r-- 2026-03-05 00:20:10
Edit Download
3.71 KB lrw-r--r-- 2026-03-05 00:20:10
Edit Download
2.33 KB lrw-r--r-- 2026-03-05 00:20:11
Edit Download
723 B lrw-r--r-- 2026-03-05 00:20:11
Edit Download
3.01 KB lrw-r--r-- 2026-03-05 00:20:11
Edit Download

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