import { fn } from "https://deno.land/x/ddc_vim@v3.8.0/deps.ts";
const { readfile } = fn;
Read file {fname} and return a List
, each line of the file
as an item. Lines are broken at NL characters. Macintosh
files separated with CR will result in a single long line
(unless a NL appears somewhere).
All NUL characters are replaced with a NL character.
When {type} contains "b" binary mode is used:
- When the last line ends in a NL an extra empty list item is added.
- No CR characters are removed. Otherwise:
- CR characters that appear before a NL are removed.
- Whether the last line ends in a NL or not does not matter.
-
- When 'encoding' is Unicode any UTF-8 byte order mark is removed from the text. When {max} is given this specifies the maximum number of lines to be read. Useful if you only want to check the first ten lines of a file:
-
for line in readfile(fname, '', 10) : if line =~ 'Date' | echo line | endif :endfor
When {max} is negative -{max} lines from the end of the file
are returned, or as many as there are.
When {max} is zero the result is an empty list.
Note that without {max} the whole file is read into memory.
Also note that there is no recognition of encoding. Read a
file into a buffer if you need to.
Deprecated (use readblob()
instead): When {type} contains
"B" a Blob
is returned with the binary data of the file
unmodified.
When the file can't be opened an error message is given and
the result is an empty list.
Also see writefile()
.
Can also be used as a method
:
GetFileName()->readfile()