xxd hex dump utility compiled to WebAssembly - works in browsers and Node.js
npm install xxd-wasmThe classic xxd hex dump utility, compiled to WebAssembly. Works in browsers and Node.js.


- Full xxd compatibility - All standard options supported
- Tiny size - Only 25KB WASM + 60KB JS
- Zero dependencies - Self-contained module
- TypeScript support - Full type definitions included
- Dual module - Works with CommonJS and ESM
``bash`
npm install xxd-wasm
`javascript
import { createXxd } from 'xxd-wasm';
const xxd = await createXxd();
// Write some data
xxd.FS.writeFile('/input.bin', new TextEncoder().encode('Hello, World!'));
// Run xxd
xxd.callMain(['/input.bin']);
// Output: 00000000: 4865 6c6c 6f2c 2057 6f72 6c64 21 Hello, World!
`
`javascript
let output = '';
const xxd = await createXxd({
print: (text) => { output += text + '\n'; },
printErr: (text) => { console.error(text); }
});
xxd.FS.writeFile('/data.bin', new Uint8Array([0x48, 0x65, 0x6c, 0x6c, 0x6f]));
xxd.callMain(['-p', '/data.bin']);
console.log(output); // "48656c6c6f\n"
`
`javascript`
xxd.callMain(['-p', '/input.bin']);
// Output: 48656c6c6f2c20576f726c6421
`javascript
xxd.callMain(['-i', '/image.png', '/image.h']);
const header = xxd.FS.readFile('/image.h', { encoding: 'utf8' });
// Output:
// unsigned char _image_png[] = {
// 0x89, 0x50, 0x4e, 0x47, ...
// };
// unsigned int _image_png_len = 1234;
`
`javascript
xxd.FS.writeFile('/hex.txt', '48656c6c6f');
xxd.callMain(['-r', '-p', '/hex.txt', '/output.bin']);
const binary = xxd.FS.readFile('/output.bin');
console.log(new TextDecoder().decode(binary)); // "Hello"
`
`javascript`
xxd.callMain(['-b', '/input.bin']);
// Output: 00000000: 01001000 01100101 01101100 01101100 01101111 Hello
Creates an xxd instance.
Options:
- print(text: string) - Handler for stdout (default: console.log)printErr(text: string)
- - Handler for stderr (default: console.error)
Returns: Promise
Run xxd with command-line arguments.
Returns: Exit code (0 = success)
Write data to the virtual filesystem.
- path - File path (e.g., '/input.bin')data
- - string or Uint8Array
Read a file from the virtual filesystem.
- path - File pathoptions.encoding
- - Set to 'utf8' to return string
Returns: Uint8Array or string
Delete a file from the virtual filesystem.
| Option | Description |
|--------|-------------|
| -a | Toggle autoskip: * replaces nul-lines |-b
| | Binary digit dump (bits instead of hex) |-c cols
| | Format octets per line (default: 16) |-C
| | Capitalize variable names in C output |-d
| | Show offset in decimal instead of hex |-e
| | Little-endian dump |-E
| | Show characters in EBCDIC |-g bytes
| | Group octets (default: 2) |-i
| | Output in C include file style |-l len
| | Stop after bytes |-n name
| | Set variable name for C output |-o off
| | Add to displayed offset |-p
| | Plain hexdump style |-r
| | Reverse: convert hex to binary |-s seek
| | Start at bytes offset |-u
| | Use uppercase hex letters |
`html`
Or with a bundler:
`javascript`
import { createXxd } from 'xxd-wasm';
`javascript
const { createXxd } = require('xxd-wasm');
// or
import { createXxd } from 'xxd-wasm';
const xxd = await createXxd();
// Read a real file
const fs = require('fs');
const data = fs.readFileSync('myfile.bin');
xxd.FS.writeFile('/myfile.bin', data);
xxd.callMain(['/myfile.bin']);
`
Requires Emscripten.
`bash
git clone https://github.com/avaitla/xxd-wasm.git
cd xxd-wasm
This project was created as a learning exercise to understand WebAssembly porting. The WebAssembly port, npm package, and web demo were primarily written by Claude (Anthropic's AI assistant), with human guidance and review.
Dual-licensed under MIT or GPL-2.0 (at your choice), same as the original xxd.
Original xxd by Juergen Weigert, with contributions from Bram Moolenaar et al.
- npm package
- GitHub repository
- Original xxd source
- Live demo