-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CompressionStream #1723
Comments
Yeah we need to do this WebKit has a CompressionStream/DecompressionStream we could use and uWebSockets (our HTTP server lib) also has builtin support for compression. Neither are wired up yet. |
Prerequisite 3b25921 |
Out of curiosity, what is the state of this issue? |
My node app uses DecompressionStream to unpack npm packages 'manually', i.e. without official npm tooling - I would very much like to switch to bun, but this is blocking me ATM. |
We just tried to port our proxy from Deno to Bun as sadly Bun doesn't support compression on its own. So we have to use https://hono.dev/middleware/builtin/compress with Bun. Is there another way to handle HTTP compression in Bun? |
any news about this issue? I also use Hono and want to use there compress middleware |
Our backend is unable to run without |
Any news about this issue? |
+1 for the same reason, though I can disable it for now it would be great to have this soon. |
One could try https://github.com/101arrowz/compression-streams-polyfill in the meantime. |
I wired up my own compression stream polyfill that is based upon zlip instead of using fflate // @bun
/*! MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */
import zlib from 'node:zlib'
// fyi, Byte streams aren't really implemented anywhere yet
// It only exist as a issue: https://github.com/WICG/compression/issues/31
const make = (ctx, handle) => Object.assign(ctx, {
writable: new WritableStream({
write: chunk => handle.write(chunk),
close: () => handle.end()
}),
readable: new ReadableStream({
type: 'bytes',
start (ctrl) {
handle.on('data', chunk => ctrl.enqueue(chunk))
handle.once('end', () => ctrl.close())
}
})
})
globalThis.CompressionStream ??= class CompressionStream {
constructor(format) {
make(this, format === 'deflate' ? zlib.createDeflate() :
format === 'gzip' ? zlib.createGzip() : zlib.createDeflateRaw())
}
}
globalThis.DecompressionStream ??= class DecompressionStream {
constructor(format) {
make(this, format === 'deflate' ? zlib.createInflate() :
format === 'gzip' ? zlib.createGunzip() :
zlib.createInflateRaw())
}
} ( this is only needed in Bun - all other env have compression stream right now... ) |
import { createGzip } from 'node:zlib'
import { Readable, pipeline } from 'node:stream'
const gzip = createGzip()
pipeline(
Readable.toWeb(process.stdin),
gzip,
process.stdout,
() => {},
) Now, you should be able to run the program with
It turns out to be a stdio issue |
Any news about this issue? |
This is a bit of a blocker for a use case I have for bun. In the meantime I can use third party packages but I hope this is supported soon. |
Before this issue is resolved you can use https://www.npmjs.com/package/bun-compression. I just ported the compression middleware that Elysia was using for hono. |
Does this bug also cover the DecompressionStream implementation? If so, can someone update the bug title? |
My deduplication backup [ddb] software uses streams with compression, specifically it |
It's on the roadmap #159 I, too, hope for a soon implementation. 🙏 |
What is the problem this feature would solve?
The compress middleware in Hono depends on CompressStream, which isn't implemented by WebKit. By adding it, it would increase the performance of transferring static assets such as CSS and SVG files.
What is the feature you are proposing to solve the problem?
Implement CompressionStream in Bun. That would automatically allow the compress middleware in Hono to work, and it would enable more Bun-optimized frameworks like Elysia to design their own middleware.
What alternatives have you considered?
It might be possible to implement CompressStream in WebKit and use that.
The text was updated successfully, but these errors were encountered: