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

◆ can_read()

bool MayaFlux::IO::SafetensorsReader::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 54 of file SafetensorsFormat.cpp.

55{
56 const auto path = resolve_path(filepath);
57 if (Detail::lower_extension(path) == "safetensors")
58 return true;
59 const auto head = Detail::read_file_head(path, 16);
60 return head && probe(head->bytes, head->file_size);
61}
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 leading bytes and file size look like a safetensors header.
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: