PHP 8.2.30
Preview: buffer-reader.ts Size: 1.41 KB
/proc/thread-self/root/home/byroehnu/.trash/node_modules11/pg-protocol/src/buffer-reader.ts

const emptyBuffer = Buffer.allocUnsafe(0)

export class BufferReader {
  private buffer: Buffer = emptyBuffer

  // TODO(bmc): support non-utf8 encoding?
  private encoding: string = 'utf-8'

  constructor(private offset: number = 0) {}

  public setBuffer(offset: number, buffer: Buffer): void {
    this.offset = offset
    this.buffer = buffer
  }

  public int16(): number {
    const result = this.buffer.readInt16BE(this.offset)
    this.offset += 2
    return result
  }

  public byte(): number {
    const result = this.buffer[this.offset]
    this.offset++
    return result
  }

  public int32(): number {
    const result = this.buffer.readInt32BE(this.offset)
    this.offset += 4
    return result
  }

  public uint32(): number {
    const result = this.buffer.readUInt32BE(this.offset)
    this.offset += 4
    return result
  }

  public string(length: number): string {
    const result = this.buffer.toString(this.encoding, this.offset, this.offset + length)
    this.offset += length
    return result
  }

  public cstring(): string {
    const start = this.offset
    let end = start
    // eslint-disable-next-line no-empty
    while (this.buffer[end++] !== 0) {}
    this.offset = end
    return this.buffer.toString(this.encoding, start, end - 1)
  }

  public bytes(length: number): Buffer {
    const result = this.buffer.slice(this.offset, this.offset + length)
    this.offset += length
    return result
  }
}

Directory Contents

Dirs: 2 × Files: 9

Name Size Perms Modified Actions
testing DIR
- drwxr-xr-x 2026-02-03 15:06:20
Edit Download
types DIR
- drwxr-xr-x 2026-02-03 15:06:18
Edit Download
473 B lrw-r--r-- 2026-02-03 15:06:18
Edit Download
1.41 KB lrw-r--r-- 2026-02-03 15:06:18
Edit Download
2.44 KB lrw-r--r-- 2026-02-03 15:06:18
Edit Download
15.04 KB lrw-r--r-- 2026-02-03 15:06:18
Edit Download
443 B lrw-r--r-- 2026-02-03 15:06:18
Edit Download
6.31 KB lrw-r--r-- 2026-02-03 15:06:18
Edit Download
8.36 KB lrw-r--r-- 2026-02-03 15:06:18
Edit Download
12.69 KB lrw-r--r-- 2026-02-03 15:06:18
Edit Download
7.02 KB lrw-r--r-- 2026-02-03 15:06:20
Edit Download

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