Parse raman WDF file.
$ npm i wdf-parser
This package is ESM-only. CommonJS consumers need Node.js >= 22.12 or any 24.x
or later, which support require() of synchronous ESM, or can migrate to
import.
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import { parse } from 'wdf-parser';
const data = readFileSync(join(import.meta.dirname, 'spectra.wdf'));
const result = parse(data);
// result is an object containing everything that was parsedparse(data) takes the content of a .wdf file (a Buffer, ArrayBuffer,
TypedArray or IOBuffer) and returns a Wdf object:
| Property | Type | Description |
|---|---|---|
fileHeader |
FileHeader |
The 512-byte file header: title, user, units, number of spectra, dates. |
blocks |
Block[] |
One entry per block found in the file, in file order. |
Each Block carries its blockType, blockSize and uuid, plus the parsed
body when the block type is supported: spectra (Float32Array[]), xList /
yList ({ type, units, values }) and origins.
const result = parse(readFileSync('6x6.wdf'));
result.fileHeader.title;
// 'Simple mapping measurement 1'
result.fileHeader.type;
// 'map'
result.blocks.map((block) => block.blockType);
// ['WDF_BLOCKID_DATA', 'WDF_BLOCKID_YLIST', 'WDF_BLOCKID_XLIST', ...]- WDF file format description — the block layout this parser reads.
- parse file header
- parse DATA block
- parse XLIST and YLIST block
- parse ORIGIN block
- parse MAPAREA
- test and write examples on this readme file
Some test files were taken from the a this Github repo.