Fix: Replace Buffer with atob for Cloudflare Workers

Buffer is not available in Workers environment. Use atob()
for base64 decoding which works in both Node.js and Workers.

Fixes ReferenceError: Buffer is not defined

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-14 20:08:04 +01:00
parent f4b2dfdb94
commit 2537b709fe

View File

@@ -12,9 +12,13 @@ export class BloomFilter {
* Creates a bloom filter from a base64 encoded bit array
*/
constructor(base64Data: string, numHashes: number = 3) {
// Decode base64 to buffer
const buffer = Buffer.from(base64Data, 'base64');
this.bits = new Uint8Array(buffer);
// Decode base64 to Uint8Array (works in both Node.js and Workers)
const binaryString = atob(base64Data);
const bytes = new Uint8Array(binaryString.length);
for (let i = 0; i < binaryString.length; i++) {
bytes[i] = binaryString.charCodeAt(i);
}
this.bits = bytes;
this.size = this.bits.length * 8;
this.numHashes = numHashes;
}