Skip to content

Repository files navigation

wdf-parser

NPM version build status Test coverage npm download

Parse raman WDF file.

Installation

$ 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.

Usage

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 parsed

API

parse(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.

Examples

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', ...]

Useful Links

ToDo

  • 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.

License

MIT

Releases

Packages

Used by

Contributors

Languages