Using zlib.deflateRaw

Is it possible to use zlib.deflateRaw? When I attempt to I get an Error 1101 Cloudflare page.
5 Replies
bnason
bnasonOP4mo ago
I've tried using the Compress Stream API as well but I get the same thing there:
async function compress(value: string, format: CompressionFormat = 'deflate-raw') {
// Convert the string to a byte stream.
const stream = new Blob([value]).stream()

// Create a compressed stream.
const compressedStream = stream.pipeThrough(new CompressionStream(format))

// Read all the bytes from this stream.
const chunks = []
for await (const chunk of compressedStream) {
chunks.push(chunk)
}

return await concatUint8Arrays(chunks)
}
async function compress(value: string, format: CompressionFormat = 'deflate-raw') {
// Convert the string to a byte stream.
const stream = new Blob([value]).stream()

// Create a compressed stream.
const compressedStream = stream.pipeThrough(new CompressionStream(format))

// Read all the bytes from this stream.
const chunks = []
for await (const chunk of compressedStream) {
chunks.push(chunk)
}

return await concatUint8Arrays(chunks)
}
Chaika
Chaika4mo ago
Workers aren't node.js, they're V8 Isolates (same js engine as chromium, web-like environment). There is some nodejs compat you can turn on (which is basically reimplemented node stuff), but that doesn't appear to include zlib at all: https://developers.cloudflare.com/workers/runtime-apis/nodejs/
Cloudflare Docs
Node.js compatibility · Cloudflare Workers docs
Implemented Node.js runtime APIs and enablement instructions for your Worker project.
Chaika
Chaika4mo ago
Tail your worker via the dashboard or wrangler to get more info on errors: https://developers.cloudflare.com/workers/observability/logging/real-time-logs/ (or use wrangler local dev)
Cloudflare Docs
Real-time logs · Cloudflare Workers docs
Debug your Worker application by accessing logs and exceptions through the Cloudflare dashboard or wrangler tail.
Chaika
Chaika4mo ago
compression streams w/ deflate-raw are supported: https://developers.cloudflare.com/workers/runtime-apis/web-standards/#compression-streams but I haven't used them enough to know what you're doing wrong by just looking at it, would have to tail and get the error to know more
bnason
bnasonOP4mo ago
ahh i think it actually worked, I was just not returning anything so I was stuck with that error page for some reason
Want results from more Discord servers?
Add your server