# ihex

> Parse Intel HEX files and load them into a Buffer. Zero runtime dependencies, ESM, TypeScript types.

Latest version **1.0.1** (published 2026-05-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install ihex
pnpm add ihex
yarn add ihex
bun add ihex
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2026-05-26 |
| First published | 2015-07-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22 |
| Dependencies | 0 |
| Unpacked size | 17.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 0 |
| Author | Cameron Tacklind |
| Maintainers | cinderblock |
| Keywords | intel-hex, ihex, hex, binary, firmware, avr, parser, embedded |

## Links

- npm: https://www.npmjs.com/package/ihex
- Repository: https://github.com/cinderblock/ihex
- Homepage: https://github.com/cinderblock/ihex#readme
- Issues: https://github.com/cinderblock/ihex/issues
- npm.io page: https://npm.io/package/ihex

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2026-05-26
- 0.3.0 — 2015-07-28
- 0.2.0 — 2015-07-27
- 0.1.0 — 2015-07-26
- 0.1.0-0 — 2015-07-18

## README

# ihex

Parse Intel HEX files and load them into a `Buffer`.

- Zero runtime dependencies (drops the abandoned `line-reader`).
- ESM, with full TypeScript declarations.
- Handles all standard record types (data, EOF, ESA, ELA, start-segment, start-linear).
- Throws on malformed lines, checksum failures, and bounds violations (configurable).

## Install

```sh
npm install ihex
```

## Quick start

```ts
import { parseFile, applyRecordsToBuffer, loadFileIntoBuffer } from 'ihex';

// One-liner: parse a .hex and write it into a Buffer.
const buf = Buffer.alloc(64 * 1024);
const highWaterMark = await loadFileIntoBuffer('firmware.hex', buf);
console.log(`Wrote ${highWaterMark} bytes`);

// Or operate on records directly.
const records = await parseFile('firmware.hex');
for (const r of records) {
  // r.byteCount, r.address, r.type, r.data
}
applyRecordsToBuffer(records, buf);
```

## API

### `parseFile(filename): Promise<IHexRecord[]>`
Read a HEX file from disk and parse its records.

### `parseString(content): IHexRecord[]`
Parse HEX content from a `string` or `Buffer`. Blank lines are skipped.

### `parseLine(line, lineNumber?): IHexRecord`
Parse a single trimmed HEX line. Throws an `IHexParseError` on bad input.

### `applyRecordsToBuffer(records, buffer, opts?): number`
Apply parsed records to a `Buffer`, honoring `ExtendedLinearAddress` and
`ExtendedSegmentAddress` records. Stops at the first `EndOfFile` record by
default. Returns the highest byte offset written.

Options:
- `stopAtEOF` (default `true`): stop processing at the EOF record.
- `strictBounds` (default `true`): throw if a data record would write past the
  buffer; when `false`, the offending bytes are silently truncated.

### `loadFileIntoBuffer(filename, buffer, opts?): Promise<number>`
Convenience: `parseFile` + `applyRecordsToBuffer` in one call.

### `IHexRecordType`
Enum-like object: `Data`, `EndOfFile`, `ExtendedSegmentAddress`,
`StartSegmentAddress`, `ExtendedLinearAddress`, `StartLinearAddress`.

### `IHexParseError`
Subclass of `Error` carrying `lineNumber` and `line` fields.

## Migrating from 0.x

The 0.x API was a single callback-style function:

```js
const ihex = require('ihex');
ihex('firmware.hex', buf, () => { /* done */ });
```

In 1.0:

```ts
import { loadFileIntoBuffer } from 'ihex';
await loadFileIntoBuffer('firmware.hex', buf);
```

Beyond the surface change, 1.0 also fixes several bugs in the original:
- Uses `Buffer.from()` instead of the deprecated and unsafe `new Buffer()`.
- Honors `ExtendedLinearAddress` records, so files larger than 64 KB load
  to the correct addresses (the 0.x code silently ignored them).
- Throws on malformed lines and checksum failures instead of `console.log`-ing
  and continuing.
- Stops at the `EndOfFile` record instead of silently mishandling it.

## Requirements

- Node.js >= 22.

## License

ISC.

---
_Source: https://npm.io/package/ihex · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
