The `leb` Node.js module provides a suite of utility functions for encoding and decoding integers using the LEB128 (Little-Endian Base 128) variable-length representation format. It supports both signed and unsigned values, with options for 32-bit integers, 64-bit integers (which return a `lossy` flag due to JavaScript's number precision limitations), and arbitrary-length buffer representations. Currently at `v1.0.0`, the package was recently resurrected and aims to provide a reliable, dependency-free solution for LEB128, a format notably used in the DWARF 3 debugging format and Android's DEX file format. The package maintains a stable API with no breaking changes in its recent major release and focuses on direct encoding/decoding operations for binary data within Node.js environments.
npm install lebVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to encode and decode both signed and unsigned 32-bit integers using `leb`, including handling offsets in a concatenated buffer.
Always check the `lossy` flag when working with 64-bit LEB128 values, and consider using `BigInt` for full precision if the library supports buffer output for 64-bit values or if you're handling large numbers manually.
For browser usage, ensure you have a `Buffer` polyfill (e.g., `buffer` npm package) or configure your bundler (like Webpack or Rollup) to correctly resolve Node.js-specific modules for browser compatibility.
Always validate the input `Buffer` and `index` to ensure enough bytes are available for a complete LEB128 value. Implement robust error handling around decoding calls to gracefully manage malformed input.
In a browser environment, you need to install and configure a `Buffer` polyfill (e.g., `npm install buffer` and import it) or ensure your bundler (Webpack, Rollup) includes one.
Ensure the input integer falls within the valid range for a 32-bit signed integer (-2,147,483,648 to 2,147,483,647) or a 32-bit unsigned integer (0 to 4,294,967,295). Use the appropriate 64-bit encoding functions (`encodeInt64`, `encodeUInt64`) for larger numbers.
Verify that the input `Buffer` contains a complete LEB128 encoded value starting from the given index. Ensure the buffer is not truncated and includes the final byte with its high bit unset.
No dependency data recorded yet.