From 2c95598ff7c4bdc0208c678fb9e09d6090c81122 Mon Sep 17 00:00:00 2001 From: Aleksei Androsov Date: Tue, 29 Apr 2025 16:48:58 +0300 Subject: [PATCH] Add support for native zstd v22.15.0+ --- lib/request.ts | 9 +++++++-- package-lock.json | 16 ++++++++-------- package.json | 2 +- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/request.ts b/lib/request.ts index 81fae82..8760d79 100644 --- a/lib/request.ts +++ b/lib/request.ts @@ -9,7 +9,7 @@ import type { ParsedUrlQueryInput } from 'querystring'; import qs_ from 'querystring'; import url_ from 'url'; import type { ZlibOptions } from 'node:zlib'; -import { createGzip, createUnzip } from 'node:zlib'; +import { createGzip, createUnzip, createZstdDecompress } from 'node:zlib'; import { decompress } from '@fengkx/zstd-napi'; import type { TransformOptions, TransformCallback } from 'stream'; import { Transform } from 'stream'; @@ -635,7 +635,12 @@ function decompressResponse(res: http.IncomingMessage) { const contentEncoding = res.headers[ 'content-encoding' ]; if (contentEncoding === 'zstd') { - return res.pipe(new ZstdDecompress()); + if (createZstdDecompress) { + // native zstd support + return res.pipe(createZstdDecompress()); + } else { + return res.pipe(new ZstdDecompress()); + } } if (contentEncoding === 'gzip' || contentEncoding === 'deflate') { diff --git a/package-lock.json b/package-lock.json index 54853cb..b2d8b49 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ "devDependencies": { "@eslint/js": "^9.21.0", "@stylistic/eslint-plugin": "^4.2.0", - "@types/node": "^22.13.10", + "@types/node": "^22.15.3", "@vitest/eslint-plugin": "^1.1.36", "eslint": "^9.22.0", "globals": "^16.0.0", @@ -1263,13 +1263,13 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "22.13.10", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.13.10.tgz", - "integrity": "sha512-I6LPUvlRH+O6VRUqYOcMudhaIdUVWfsjnZavnsraHvpBwaEyMN29ry+0UVJhImYL16xsscu0aske3yA+uPOWfw==", + "version": "22.15.3", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.15.3.tgz", + "integrity": "sha512-lX7HFZeHf4QG/J7tBZqrCAXwz9J5RD56Y6MpP0eJkka8p+K0RY/yBTW7CYFJ4VGCclxqOLKmiGP5juQc6MKgcw==", "dev": true, "license": "MIT", "dependencies": { - "undici-types": "~6.20.0" + "undici-types": "~6.21.0" } }, "node_modules/@typescript-eslint/scope-manager": { @@ -3016,9 +3016,9 @@ } }, "node_modules/undici-types": { - "version": "6.20.0", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz", - "integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==", + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz", + "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==", "dev": true, "license": "MIT" }, diff --git a/package.json b/package.json index fc44e8c..f4132c5 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "devDependencies": { "@eslint/js": "^9.21.0", "@stylistic/eslint-plugin": "^4.2.0", - "@types/node": "^22.13.10", + "@types/node": "^22.15.3", "@vitest/eslint-plugin": "^1.1.36", "eslint": "^9.22.0", "globals": "^16.0.0",