Skip to content

LocalFileWrapper

Eugene Lazutkin edited this page Jun 25, 2026 · 1 revision

LocalFileWrapper

A local-filesystem ObjectStreamWrapper. Items are framed as line-delimited text — JSON.stringify(item) + '\n' by default. This is the wrapper sort and polyphaseSort use when you pass tmpDir.

import {LocalFileWrapper} from 'stream-sorting';

const wrapper = new LocalFileWrapper({path: '/var/sort/run-0.jsonl'});

Options

Option Type Default Description
path string Path to the backing file. Required.
serialize (item) => string JSON.stringify Per-item encoder. The result must not contain \n (the framing is line-delimited).
deserialize (text) => item JSON.parse Per-item decoder; receives one line without the trailing \n.

Override serialize / deserialize for a non-JSON encoding (e.g. a compact binary form). path has no default: Linux /tmp is commonly RAM-backed (tmpfs), which would silently defeat a disk-backed sort. The instance exposes a read-only path property.

See also: ObjectStreamWrapper, MemoryWrapper.

Clone this wiki locally