From 9b2adc97d075d3fe4f41f77cfcb88a6a25b9ecfa Mon Sep 17 00:00:00 2001 From: Sebastian Hengst Date: Thu, 18 Jan 2024 19:52:08 +0100 Subject: [PATCH] Bug 1875340 - use JavaScript's DecompressionStream instead of 'pako' package --- package.json | 1 - tests/ui/helpers/gzip_test.js | 12 ------------ ui/helpers/gzip.js | 16 ++++++++-------- ui/job-view/pushes/Push.jsx | 3 +-- 4 files changed, 9 insertions(+), 23 deletions(-) delete mode 100644 tests/ui/helpers/gzip_test.js diff --git a/package.json b/package.json index 9a1c0762173..f1d2203bd82 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,6 @@ "mobx": "6.10.2", "moment": "2.29.4", "numeral": "2.0.6", - "pako": "2.0.4", "prop-types": "15.7.2", "query-string": "7.0.1", "react": "17.0.2", diff --git a/tests/ui/helpers/gzip_test.js b/tests/ui/helpers/gzip_test.js deleted file mode 100644 index 02f67411cac..00000000000 --- a/tests/ui/helpers/gzip_test.js +++ /dev/null @@ -1,12 +0,0 @@ -import { gzip } from 'pako'; - -import decompress from '../../../ui/helpers/gzip'; - -describe('gzip related functions', () => { - test('compress and decompress', async () => { - const str = JSON.stringify({ foo: 'bar' }); - const compressed = await gzip(str); - const decompressed = await decompress(compressed); - expect(JSON.stringify(decompressed)).toBe(str); - }); -}); diff --git a/ui/helpers/gzip.js b/ui/helpers/gzip.js index 38daa01d273..7817e0dcbf2 100644 --- a/ui/helpers/gzip.js +++ b/ui/helpers/gzip.js @@ -1,8 +1,8 @@ -import { inflate } from 'pako'; - -export const unGzip = async (binData) => { - const decompressed = await inflate(binData, { to: 'string' }); - return JSON.parse(decompressed); -}; - -export default unGzip; +export default async function unGzip(blob) { + const decompressionStream = new DecompressionStream('gzip'); + const decompressedStream = blob.stream().pipeThrough(decompressionStream); + const payloadText = await ( + await new Response(decompressedStream).blob() + ).text(); + return JSON.parse(payloadText); +} diff --git a/ui/job-view/pushes/Push.jsx b/ui/job-view/pushes/Push.jsx index d28ff045c48..8a3b4c679af 100644 --- a/ui/job-view/pushes/Push.jsx +++ b/ui/job-view/pushes/Push.jsx @@ -79,8 +79,7 @@ const fetchGeckoDecisionArtifact = async (project, revision, filePath) => { if (url.endsWith('.gz')) { if ([200, 303, 304].includes(response.status)) { const blob = await response.blob(); - const binData = await blob.arrayBuffer(); - artifactContents = await decompress(binData); + artifactContents = await decompress(blob); } } else if (url.endsWith('.json')) { if ([200, 303, 304].includes(response.status)) {