keryx 0.14.1 → 0.14.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/util/webCompression.ts +8 -4
package/package.json
CHANGED
package/util/webCompression.ts
CHANGED
|
@@ -111,15 +111,16 @@ export async function compressResponse(
|
|
|
111
111
|
// Compress the buffered body
|
|
112
112
|
const format: Bun.CompressionFormat = encoding === "br" ? "brotli" : "gzip";
|
|
113
113
|
// @ts-ignore Bun supports "brotli" as CompressionFormat but DOM lib does not
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
114
|
+
const compressionStream = new CompressionStream(format);
|
|
115
|
+
// @ts-ignore Bun's ReadableStream type is incompatible with Node/DOM ReadableStream
|
|
116
|
+
const stream = new Blob([body]).stream().pipeThrough(compressionStream);
|
|
117
117
|
|
|
118
118
|
const headers = new Headers(response.headers);
|
|
119
119
|
headers.set("Content-Encoding", encoding);
|
|
120
120
|
headers.append("Vary", "Accept-Encoding");
|
|
121
121
|
headers.delete("Content-Length");
|
|
122
122
|
|
|
123
|
+
// @ts-ignore Bun's ReadableStream type is incompatible with Node/DOM ReadableStream
|
|
123
124
|
return new Response(stream, {
|
|
124
125
|
status: response.status,
|
|
125
126
|
headers,
|
|
@@ -129,13 +130,16 @@ export async function compressResponse(
|
|
|
129
130
|
// Content-Length is present and above threshold — stream-compress
|
|
130
131
|
const format: Bun.CompressionFormat = encoding === "br" ? "brotli" : "gzip";
|
|
131
132
|
// @ts-ignore Bun supports "brotli" as CompressionFormat but DOM lib does not
|
|
132
|
-
const
|
|
133
|
+
const compressionStream = new CompressionStream(format);
|
|
134
|
+
// @ts-ignore Bun's ReadableStream type is incompatible with Node/DOM ReadableStream
|
|
135
|
+
const stream = response.body.pipeThrough(compressionStream);
|
|
133
136
|
|
|
134
137
|
const headers = new Headers(response.headers);
|
|
135
138
|
headers.set("Content-Encoding", encoding);
|
|
136
139
|
headers.append("Vary", "Accept-Encoding");
|
|
137
140
|
headers.delete("Content-Length");
|
|
138
141
|
|
|
142
|
+
// @ts-ignore Bun's ReadableStream type is incompatible with Node/DOM ReadableStream
|
|
139
143
|
return new Response(stream, {
|
|
140
144
|
status: response.status,
|
|
141
145
|
headers,
|