Skip to content

Commit ed1ac7a

Browse files
committed
Switch from gzip to deflate for compression
Resolves #2796
1 parent 9dcbd5d commit ed1ac7a

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ title: Changelog
66

77
### Bug Fixes
88

9+
- Switch from gzip to deflate for compressing assets to make output consistent across different operating systems, #2796.
910
- Cascaded modifier tags will no longer be copied into type literals, #2802.
1011

1112
## v0.27.3 (2024-12-04)
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/**
2-
* Decompresses Base64-encoded Gzip data and parses it into a JSON object.
2+
* Decompresses Base64-encoded deflate compressed data and parses it into a JSON object.
33
*
4-
* @param base64 - The Base64-encoded string representing the Gzip-compressed JSON string.
4+
* @param base64 - The Base64-encoded string representing the deflate-compressed JSON string.
55
* @returns A promise that resolves to the parsed JSON object.
66
*/
77
export async function decompressJson(base64: string) {
88
const binaryData = Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
99
const blob = new Blob([binaryData]);
1010
const decompressedStream = blob
1111
.stream()
12-
.pipeThrough(new DecompressionStream("gzip"));
12+
.pipeThrough(new DecompressionStream("deflate"));
1313
const decompressedText = await new Response(decompressedStream).text();
1414
return JSON.parse(decompressedText);
1515
}

src/lib/utils/compress.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { gzip } from "zlib";
1+
import { deflate } from "zlib";
22
import { promisify } from "util";
33

4-
const gzipP = promisify(gzip);
4+
const deflateP = promisify(deflate);
55

66
/**
7-
* Compresses a JSON-serializable object into a Base64-encoded Gzip string.
7+
* Compresses a JSON-serializable object into a Base64-encoded deflate string.
88
*
99
* @param data - The JSON-serializable object to compress.
10-
* @returns A promise that resolves to a Base64-encoded string of the Gzip-compressed data.
10+
* @returns A promise that resolves to a Base64-encoded string of the deflate-compressed data.
1111
*/
1212
export async function compressJson(data: any) {
13-
const gz = await gzipP(Buffer.from(JSON.stringify(data)));
13+
const gz = await deflateP(Buffer.from(JSON.stringify(data)));
1414
return gz.toString("base64");
1515
}

0 commit comments

Comments
 (0)