@@ -1,6 +1,7 @@
|
||||
/**
|
||||
* Diagnose a GGUF on disk after load failure (magic / size / sha256).
|
||||
*/
|
||||
import b4a from 'b4a'
|
||||
|
||||
/** @type {Record<string, { size: number, sha256: string }>} */
|
||||
export const BARE_OS_QVAC_KNOWN_GGUF = {
|
||||
@@ -24,12 +25,7 @@ export async function bareOsQvacDiagnoseGguf(filePath) {
|
||||
/** @type {string[]} */
|
||||
const lines = ['gguf path: ' + p]
|
||||
try {
|
||||
let fs
|
||||
try {
|
||||
fs = await import('bare-fs')
|
||||
} catch {
|
||||
fs = await import('fs')
|
||||
}
|
||||
const fs = await import('bare-fs')
|
||||
const fsp = fs.promises || fs
|
||||
const st = await fsp.stat(p)
|
||||
lines.push('size: ' + st.size + ' bytes')
|
||||
@@ -49,7 +45,7 @@ export async function bareOsQvacDiagnoseGguf(filePath) {
|
||||
)
|
||||
}
|
||||
|
||||
const buf = Buffer.alloc(4)
|
||||
const buf = new Uint8Array(4)
|
||||
let fh
|
||||
try {
|
||||
if (typeof fsp.open === 'function') {
|
||||
@@ -73,17 +69,12 @@ export async function bareOsQvacDiagnoseGguf(filePath) {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
const magic = buf.toString('utf8')
|
||||
const magic = b4a.toString(buf, 'utf8')
|
||||
lines.push('magic: ' + JSON.stringify(magic) + (magic === 'GGUF' ? ' (ok)' : ' (BAD)'))
|
||||
|
||||
if (known && st.size === known.size && st.size <= 2 * 1024 * 1024 * 1024) {
|
||||
try {
|
||||
let crypto
|
||||
try {
|
||||
crypto = await import('bare-crypto')
|
||||
} catch {
|
||||
crypto = await import('crypto')
|
||||
}
|
||||
const crypto = await import('bare-crypto')
|
||||
const createHash = crypto.createHash || crypto.default?.createHash
|
||||
if (typeof createHash === 'function') {
|
||||
const hash = createHash('sha256')
|
||||
|
||||
Reference in New Issue
Block a user