head, tail, wc -l and tail -f can ask your VFS for lines or a count,
instead of reading the file. Return exactly what a read would hold, or None
(TypeScript: null) and Mirage reads the file.
For example, PostgreSQL answers
head -n 20 rows.jsonl with LIMIT 20 and wc -l rows.jsonl with
COUNT(*).
first_lines
The first lines of one file.
- Python
- TypeScript
These commands call
first_lines:
head: the first 10 lineshead -n N,head -N: the first N lines
head -c N: the first N byteshead -n -N: all but the last N lineshead -z: lines end with NUL- standard input
last_lines
The last lines of one file.
- Python
- TypeScript
These commands call
last_lines:
tail: the last 10 linestail -n N,tail -N: the last N lines
tail -c N: the last N bytestail -n +N: from line N on- standard input
line_count
The number of lines in one file.
- Python
- TypeScript
This command calls
line_count:
wc -l
wcwith another count:-c,-w,-mor-L- standard input
Example: head, tail and wc -l
This example extendsNotesVFS from Custom VFS:
- Python
- TypeScript
head -n 1, tail -n 1 and wc -l on a page then read nothing. head -c 3
still reads it.
follow
The last lines of one file, then each new line as it arrives.
- Python
- TypeScript
These commands call
follow:
tail -f,tail -f -n Non one file
interval seconds instead:
tail -F,tail --follow=name: follow the name, not the filetail -f -c Ntail -f -n +Ntail -fon more than one file
NotesVFS. A real service would push new lines
over a stream; this one checks the dictionary every interval seconds. It
yields on every check, an empty chunk when nothing is new, so a stopped
tail -f closes it within one interval, and it starts over when the page
shrinks:
- Python
- TypeScript