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

◆ read_file_head()

std::optional< FileHead > MayaFlux::IO::Detail::read_file_head ( const std::string & path,
size_t limit )
nodiscard

Read up to limit leading bytes of a file, or std::nullopt if it cannot be opened.

Definition at line 184 of file TensorCodec.cpp.

185{
186 std::ifstream file(path, std::ios::binary);
187 if (!file)
188 return std::nullopt;
189
190 file.seekg(0, std::ios::end);
191 FileHead head;
192 head.file_size = static_cast<uint64_t>(file.tellg());
193 file.seekg(0);
194
195 head.bytes.resize(static_cast<size_t>(std::min<uint64_t>(limit, head.file_size)));
196 file.read(reinterpret_cast<char*>(head.bytes.data()), static_cast<std::streamsize>(head.bytes.size()));
197 head.bytes.resize(static_cast<size_t>(file.gcount()));
198 return head;
199}
std::vector< std::byte > bytes
First bytes of a file together with its total size.

References MayaFlux::IO::Detail::FileHead::bytes, and MayaFlux::IO::Detail::FileHead::file_size.

Referenced by MayaFlux::IO::NpyReader::can_read(), MayaFlux::IO::SafetensorsReader::can_read(), and MayaFlux::IO::TensorFormatRegistry::detect().

Here is the caller graph for this function: