Gives a file's whole content as Map_File_Info.data; returns ok as false and empty data when the file cannot be read.
map_entire_file_start :: (
name: string,
log_errors := false
) -> (Map_File_Info, bool)
The content is read-only and must be released with map_entire_file_end. On Windows it is mapped, so a large file costs
no copy and the file stays open until the end call; elsewhere it is read into memory, as read_entire_file does.
log_errors = true reports an open failure through context.logger.
Parameters
- name: string
- log_errors := false
Returns
- bool
#import "Extensions/Environment";
base := environment_variable("TMPDIR");
if base == "" base = environment_variable("TEMP");
if base == "" base = "/tmp";
path := tprint("%/jai-doc-map-file.txt", base);
defer file_delete(path);
assert(write_entire_file(path, "mapped text"));
info, ok := map_entire_file_start(path);
assert(ok && info.data == "mapped text");
map_entire_file_end(*info);
assert(info.data.count == 0);