fix(xva): missing await

This commit is contained in:
Florent Beauchamp
2024-02-05 13:35:22 +00:00
committed by Julien Fontanet
parent 5c731fd56e
commit 4d24248ea2

View File

@@ -5,15 +5,20 @@ import { xxhash64 } from 'hash-wasm'
export const XVA_DISK_CHUNK_LENGTH = 1024 * 1024
async function addEntry(pack, name, buffer) {
await fromCallback.call(pack, pack.entry, { name }, buffer)
}
async function writeBlock(pack, data, name) {
if (data.length < XVA_DISK_CHUNK_LENGTH) {
data = Buffer.concat([data, Buffer.alloc(XVA_DISK_CHUNK_LENGTH - data.length, 0)])
}
await fromCallback.call(pack, pack.entry, { name }, data)
await addEntry(pack, name, data)
// weirdly, ocaml and xxhash return the bytes in reverse order to each other
const hash = (await xxhash64(data)).toString('hex').toUpperCase()
await fromCallback.call(pack, pack.entry, { name: `${name}.xxhash` }, Buffer.from(hash, 'utf8'))
await addEntry(pack, `${name}.xxhash`, Buffer.from(hash, 'utf8'))
}
export default async function addDisk(pack, vhd, basePath) {
let counter = 0
let written
@@ -47,6 +52,6 @@ export default async function addDisk(pack, vhd, basePath) {
}
if (!written) {
// last block must be present
writeBlock(pack, empty, `${basePath}/${('' + counter).padStart(8, '0')}`)
await writeBlock(pack, empty, formatBlockPath(basePath, counter))
}
}