folly::readFile

readFile overloads

Synopses

Declared in <folly/FileUtil.h>

Read entire file (if num_bytes is defaulted) or no more than num_bytes (otherwise) into container *out. The container is assumed to be contiguous, with element size equal to 1, and offer size(), reserve(), and random access (e.g. std::vector<char>, std::string, fbstring).

template<class Container>
bool
readFile(
    int fd,
    Container& out,
    size_t num_bytes = std::numeric_limits<size_t>::max());
» more...

Same as above, but takes a std::filesystem::path instead of fd

template<class Container>
requires (std::same_as<std::filesystem::path::value_type, char>)
bool
readFile(
    std::filesystem::path const& path,
    Container& out,
    size_t num_bytes = std::numeric_limits<size_t>::max());
» more...

Same as above, but takes in a file name instead of fd

template<class Container>
bool
readFile(
    char const* file_name,
    Container& out,
    size_t num_bytes = std::numeric_limits<size_t>::max());
» more...

Return Value

True on success, false on failure.

Parameters

NameDescription
fdThe file descriptor to read from.
outThe container that the file contents are read into.
num_bytesMaximum number of bytes to read.
pathPath of the file to read.
file_namePath of the file to read.