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, orNone (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.
Examples:
- Python
- TypeScript
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.
Examples:
- Python
- TypeScript
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.
Examples:
- Python
- TypeScript
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.
The seconds between two checks for new lines. A service that pushes new lines can ignore it.
- Python
- TypeScript
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.