Initializing playground…
← Back to roadmap

🗂️ HDF5 I/O

readHdf(data, options?) and toHdf(df, options?) implement a pure-TypeScript HDF5 v0 Superblock reader and writer with no native dependencies. Each file encodes a single DataFrame under a configurable HDF5 group key (default "df"). The format is compatible with pandas.read_hdf() / DataFrame.to_hdf().

Supported column types: Float64/Float32, Int8/16/32/64, UInt8/16/32/64, Bool (stored as UInt8), String (fixed-length null-padded UTF-8). Max 120 columns per DataFrame. One DataFrame per file (single HDF5 group key).

1 · Basic read & write

Serialize a DataFrame to an HDF5 binary buffer with toHdf() and read it back with readHdf(). The buffer begins with the standard HDF5 magic bytes 0x89 HDF\r\n\x1a\n.

TypeScript
Click ▶ Run to execute

2 · Column types — int, float, boolean, string

HDF5 stores numeric types as contiguous fixed-width binary arrays. Booleans are stored as UInt8 (0 or 1). Strings are fixed-length null-padded UTF-8 — the element size is the byte length of the longest string in the column.

TypeScript
Click ▶ Run to execute

3 · Custom HDF5 group key

The HDF5 group key specifies where within the file the DataFrame is stored. The default is "df". A leading / is stripped automatically (both in write and read).

TypeScript
Click ▶ Run to execute

4 · usecols — selective column reads

Pass usecols to read only a subset of columns from the file. Unselected columns are skipped during dataset parsing.

TypeScript
Click ▶ Run to execute

5 · writeIndex & indexCol — persisting the row index

Use writeIndex: true to store the DataFrame's row index as an extra column named __index__. When reading back, pass indexCol: "__index__" to restore it as the row index.

TypeScript
Click ▶ Run to execute

6 · Unicode strings

Strings are stored as fixed-length null-padded UTF-8 arrays. The element size is the byte length of the longest encoded string. Any Unicode string — including emoji, CJK, and accented characters — round-trips exactly.

TypeScript
Click ▶ Run to execute

7 · Special float values — NaN, Infinity

IEEE 754 special values round-trip correctly since the data is stored as raw binary float64 without any encoding layer.

TypeScript
Click ▶ Run to execute