fix: wrong size oshash
This commit is contained in:
parent
a99b62a229
commit
e00c888d7b
@ -20,7 +20,18 @@ export async function oshash(
|
|||||||
let hash = BigInt(st.size);
|
let hash = BigInt(st.size);
|
||||||
|
|
||||||
if (st.size < minFileSize){
|
if (st.size < minFileSize){
|
||||||
throw new Error("File is too small to hash");
|
// Although the original oshash algorithm should throw an exception,
|
||||||
|
// just applying the hash function.
|
||||||
|
const chunk = new Uint8Array(st.size);
|
||||||
|
await fd.read(chunk, 0, st.size, 0);
|
||||||
|
const chunkView = new DataView(chunk.buffer);
|
||||||
|
for (let i = 0; i < Math.floor(st.size / 8) * 8 ; i += 8) {
|
||||||
|
hash += chunkView.getBigUint64(i, true);
|
||||||
|
hash *= 65537n; // 2^16 + 1
|
||||||
|
hash = (hash & 0xFFFFFFFFFFFFFFFFn);
|
||||||
|
}
|
||||||
|
fd.close();
|
||||||
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
// read first and last chunk
|
// read first and last chunk
|
||||||
|
Loading…
Reference in New Issue
Block a user