MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ can_read()

bool MayaFlux::IO::NpyReader::can_read ( const std::string & filepath) const
nodiscardoverridevirtual

Check if a file can be read by this reader.

Parameters
filepathPath to the file.
Returns
true if the file format is supported.

Implements MayaFlux::IO::FileReader.

Definition at line 29 of file NpyFormat.cpp.

30{
31 const auto path = resolve_path(filepath);
32 if (Detail::lower_extension(path) == "npy") {
33 return true;
34 }
35 const auto head = Detail::read_file_head(path, 12);
36 return head && probe(head->bytes, head->file_size);
37}
static std::string resolve_path(const std::string &filepath)
Resolve a filepath against the project source root if not found as-is.
static bool probe(std::span< const std::byte > head, uint64_t file_size)
Whether the leading bytes are the numpy magic string.
Definition NpyFormat.cpp:23
std::string lower_extension(const std::string &path)
Lowercase extension of a path without its dot.
std::optional< FileHead > read_file_head(const std::string &path, size_t limit)
Read up to limit leading bytes of a file, or std::nullopt if it cannot be opened.

References MayaFlux::IO::Detail::lower_extension(), probe(), MayaFlux::IO::Detail::read_file_head(), and MayaFlux::IO::FileReader::resolve_path().

Here is the call graph for this function: