Skip to main content
Lines lets a VFS answer head, tail, wc -l and tail -f without reading the whole file. Built-in VFSs lists which VFSs support it.

VFS and Lines Integration

A VFS overrides the methods its service can answer. Each method returns exactly what a read would hold, or None (TypeScript: null) when it cannot answer, and Mirage reads the file instead. TypeScript names methods in camelCase (first_lines is firstLines) and returns Uint8Array for bytes. A command reading standard input never asks. The examples extend NotesVFS from Adding a New VFS, mounted at /notes.

first_lines

The first lines of one file. Commands: head, head -n N and head -N. head -c N, head -n -N and head -z read the file without asking.
PathSpec
required
The file, on this mount.
int
required
How many lines to return, 1 or more.
Examples:
bytes | None
With this example, head -n 1 on a page reads nothing, and head -c 3 still reads it.

last_lines

The last lines of one file. Commands: tail, tail -n N and tail -N. tail -c N and tail -n +N read the file without asking.
PathSpec
required
The file, on this mount.
int
required
How many lines to return, 1 or more.
Examples:
bytes | None

line_count

The number of lines in one file. Commands: wc -l. wc with another count (-c, -w, -m or -L) reads the file without asking.
PathSpec
required
The file, on this mount.
Examples:
int | None

follow

The last lines of one file, then each new line as it arrives. Commands: tail -f and tail -f -n N on one file. tail -F, tail --follow=name, tail -f -c N, tail -f -n +N and tail -f on more than one file read the file every interval seconds without asking.
PathSpec
required
The file, on this mount.
int
required
How many of the file’s last lines to send first, 0 for none.
float
required
The seconds between two checks for new lines. A service that pushes new lines can ignore it.
Examples:
AsyncIterator[bytes] | None
A real service would push new lines over a stream. This example checks the dictionary every interval seconds instead. It yields on every check, an empty chunk when nothing is new, so a stopped tail -f closes it within one interval. It starts over when the page shrinks.