From 2537b709feda0c2ad5b5fc725d0cffa71d18e8db Mon Sep 17 00:00:00 2001 From: Bas van den Aakster Date: Fri, 14 Nov 2025 20:08:04 +0100 Subject: [PATCH] Fix: Replace Buffer with atob for Cloudflare Workers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/bloom.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/bloom.ts b/src/bloom.ts index bab94e2..0e0af2e 100644 --- a/src/bloom.ts +++ b/src/bloom.ts @@ -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; }