diff --git a/packages/server/src/util/oshash.ts b/packages/server/src/util/oshash.ts index f044738..1dd78cb 100644 --- a/packages/server/src/util/oshash.ts +++ b/packages/server/src/util/oshash.ts @@ -20,7 +20,18 @@ export async function oshash( let hash = BigInt(st.size); 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