| 44 | // Identifies a tensor container from its leading bytes. Returns nullopt when the file is unreadable or |
| 45 | // matches no known container. Torch checkpoints are not sniffed: they are ZIP or pickle streams that |
| 46 | // cannot be told apart reliably from other files. |
| 47 | std::optional<TensorContainer> sniff_tensor_container(const std::filesystem::path & path) { |
| 48 | std::ifstream in(path, std::ios::binary); |
| 49 | if (!in) return std::nullopt; |
| 50 | char head[9] = {}; |
| 51 | in.read(head, sizeof(head)); |
| 52 | const auto count = in.gcount(); |
| 53 | if (count >= 4 && std::memcmp(head, "GGUF", 4) == 0) return TensorContainer::Gguf; |
| 54 | // Safetensors: little-endian u64 header size, followed by a JSON object. |
| 55 | if (count == 9 && head[8] == '{') { |
no outgoing calls
no test coverage detected