BinaryReader (advanced)

BinaryReader is the low-level byte-stream reader used internally by the parser. It is exported for advanced use cases such as building custom EFLR processors or inspecting raw record bodies.

import { BinaryReader } from '@geoharkat/dlis-parser';

const r = new BinaryReader(myUint8Array);
const origin = r.uvari();
const name   = r.ident();

Constructor

new BinaryReader(source[, start[, end]])
Arguments:
  • source (ArrayBuffer|Uint8Array) – The raw byte data to read from.

  • start (number) – Byte offset to begin reading at (default 0).

  • end (number) – Exclusive end offset (default: length of source).

Position

BinaryReader.pos

Current read position relative to start. Writable — you can seek by assigning a new value.

Type:

number

BinaryReader.rem

Remaining bytes from the current position to end.

Type:

number

BinaryReader.eof()
Returns:

true when the read position has reached end.

Return type:

boolean

BinaryReader.peek()

Return the next byte without advancing the position, or -1 at EOF.

Return type:

number

Primitive readers

All multi-byte integers and floats are big-endian per the RP66 V1 specification.

Method

Returns

Description

u8()

number

1-byte unsigned integer

u16()

number

2-byte unsigned integer (big-endian)

u32()

number

4-byte unsigned integer (big-endian)

i8()

number

1-byte signed integer

i16()

number

2-byte signed integer (big-endian)

i32()

number

4-byte signed integer (big-endian)

f32()

number

4-byte IEEE 754 float (big-endian)

f64()

number

8-byte IEEE 754 double (big-endian)

skip(n)

void

Advance position by n bytes

slice(n)

Uint8Array

Return zero-copy view of next n bytes and advance

text(n)

string

Decode next n bytes as UTF-8

RP66 V1 structured types

BinaryReader.fshort()

Read a 16-bit RP66 short float (not IEEE half-float).

Return type:

number

BinaryReader.isingl()

Read a 4-byte IBM base-16 single-precision float.

Return type:

number

BinaryReader.vsingl()

Read a 4-byte VAX F-float (word-swapped pairs).

Return type:

number

BinaryReader.uvari()

Read a variable-length unsigned integer: 1 byte if b0 < 0x80, 2 bytes if b0 & 0xC0 == 0x80, otherwise 4 bytes.

Return type:

number

BinaryReader.ident()

Read a 1-byte length-prefixed ASCII string (max 255 bytes).

Return type:

string

BinaryReader.asciiStr()

Read a 4-byte length-prefixed ASCII string. Automatically falls back to ident() when the 4-byte length field is unreasonably large (> 65536), which handles vendors that write IDENT-encoded strings with ASCII repcodes.

Return type:

string

BinaryReader.obname()

Read an OBNAME triplet { origin, copy, name }. Auto-detects the standard 2-byte copy field and the Baker Hughes 1-byte variant.

Return type:

OBName

BinaryReader.objref()

Read an OBJREF: { type: string, name: OBName }.

Return type:

object

BinaryReader.dtime()

Read an 8-byte RP66 V1 date-time value.

Return type:

Date

BinaryReader.val(rc)

Dispatch to the correct reader for representation code rc. Covers all 27 RP66 V1 codes. Throws Error for unknown codes.

Arguments:
  • rc (number) – Representation code (use the RC enum).

Return type:

number | string | boolean | Date | OBName | object