new features

This commit is contained in:
Mark Gregory
2026-11-18 13:55:47 +00:00
parent 17bcf178a9
commit a07ddf4d6d
29 changed files with 3457 additions and 306 deletions
+28
View File
@@ -0,0 +1,28 @@
import Foundation
enum GGUFHeader {
enum ValidationError: LocalizedError {
case invalidMagic
case unsupportedVersion(UInt32)
var errorDescription: String? {
switch self {
case .invalidMagic: "The file does not have a valid GGUF header."
case .unsupportedVersion(let version): "GGUF version \(version) is unsupported."
}
}
}
static func version(in data: Data) throws -> UInt32 {
guard data.count >= 8, data.prefix(4).elementsEqual("GGUF".utf8) else {
throw ValidationError.invalidMagic
}
let version = data.withUnsafeBytes { bytes in
UInt32(littleEndian: bytes.loadUnaligned(fromByteOffset: 4, as: UInt32.self))
}
guard version == 2 || version == 3 else {
throw ValidationError.unsupportedVersion(version)
}
return version
}
}