headFile
Requires a Node.js runtime ('qsu/node')Returns the first line of the specified text file path. The length argument is the total number of lines to print. Default is 1.
Only as much of the file as the requested lines need is read, so the cost does not follow the size of the file.
A line breaks on \n, \r\n or a lone \r. Bytes that are not valid UTF-8 become the replacement character U+FFFD instead of raising, and a leading byte order mark is kept.
Parameters
| Name | Type | Required | Default |
|---|---|---|---|
filePath | stringStringstr | ● | – |
| File or directory path | |||
length named keyword | numberint | – | 1 |
| Number of lines of text to return | |||
namedThese parameters are passed as named parameters.
keywordThese parameters are passed as keyword arguments, or as a single dict in their place.
Returns
Promise<string | null>
Future<String?>
str | None
Examples
javascript
await headFile('/home/targets/hello.md', 2); // '# Hello, World!\nSecond line'dart
await headFile('/home/targets/hello.md', length: 2); // '# Hello, World!\nSecond line'python
headFile('/home/targets/hello.md', 2) # '# Hello, World!\nSecond line'