@whatwg-node/node-fetch 0.8.3-alpha-20251110161950-a399c572806c26a67ae5f1b3dbb21cac7461155a → 0.8.3-alpha-20251110204347-16d19b0f9727cc130885edd3d0d9a79139ac963a

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.
@@ -4,10 +4,9 @@ exports.PonyfillCompressionStream = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const node_zlib_1 = tslib_1.__importDefault(require("node:zlib"));
6
6
  const TransformStream_js_1 = require("./TransformStream.js");
7
+ const utils_js_1 = require("./utils.js");
7
8
  class PonyfillCompressionStream extends TransformStream_js_1.PonyfillTransformStream {
8
- static supportedFormats = globalThis.process?.version?.startsWith('v2')
9
- ? ['gzip', 'deflate', 'br', 'zstd']
10
- : ['gzip', 'deflate', 'deflate-raw', 'br'];
9
+ static supportedFormats = (0, utils_js_1.getSupportedFormats)();
11
10
  constructor(compressionFormat) {
12
11
  switch (compressionFormat) {
13
12
  case 'x-gzip':
@@ -4,10 +4,9 @@ exports.PonyfillDecompressionStream = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const node_zlib_1 = tslib_1.__importDefault(require("node:zlib"));
6
6
  const TransformStream_js_1 = require("./TransformStream.js");
7
+ const utils_js_1 = require("./utils.js");
7
8
  class PonyfillDecompressionStream extends TransformStream_js_1.PonyfillTransformStream {
8
- static supportedFormats = globalThis.process?.version?.startsWith('v2')
9
- ? ['gzip', 'deflate', 'br', 'zstd']
10
- : ['gzip', 'deflate', 'deflate-raw', 'br'];
9
+ static supportedFormats = (0, utils_js_1.getSupportedFormats)();
11
10
  constructor(compressionFormat) {
12
11
  switch (compressionFormat) {
13
12
  case 'x-gzip':
package/cjs/utils.js CHANGED
@@ -10,7 +10,10 @@ exports.shouldRedirect = shouldRedirect;
10
10
  exports.pipeThrough = pipeThrough;
11
11
  exports.endStream = endStream;
12
12
  exports.safeWrite = safeWrite;
13
+ exports.getSupportedFormats = getSupportedFormats;
14
+ const tslib_1 = require("tslib");
13
15
  const node_events_1 = require("node:events");
16
+ const node_zlib_1 = tslib_1.__importDefault(require("node:zlib"));
14
17
  function isHeadersInstance(obj) {
15
18
  return obj?.forEach != null;
16
19
  }
@@ -109,3 +112,13 @@ class AbortError extends Error {
109
112
  this.name = 'AbortError';
110
113
  }
111
114
  }
115
+ function getSupportedFormats() {
116
+ const baseFormats = ['gzip', 'deflate', 'br'];
117
+ if (!globalThis.process?.versions?.node?.startsWith('2')) {
118
+ baseFormats.push('deflate-raw');
119
+ }
120
+ if (node_zlib_1.default.createZstdCompress != null) {
121
+ baseFormats.push('zstd');
122
+ }
123
+ return baseFormats;
124
+ }
@@ -1,9 +1,8 @@
1
1
  import zlib from 'node:zlib';
2
2
  import { PonyfillTransformStream } from './TransformStream.js';
3
+ import { getSupportedFormats } from './utils.js';
3
4
  export class PonyfillCompressionStream extends PonyfillTransformStream {
4
- static supportedFormats = globalThis.process?.version?.startsWith('v2')
5
- ? ['gzip', 'deflate', 'br', 'zstd']
6
- : ['gzip', 'deflate', 'deflate-raw', 'br'];
5
+ static supportedFormats = getSupportedFormats();
7
6
  constructor(compressionFormat) {
8
7
  switch (compressionFormat) {
9
8
  case 'x-gzip':
@@ -1,9 +1,8 @@
1
1
  import zlib from 'node:zlib';
2
2
  import { PonyfillTransformStream } from './TransformStream.js';
3
+ import { getSupportedFormats } from './utils.js';
3
4
  export class PonyfillDecompressionStream extends PonyfillTransformStream {
4
- static supportedFormats = globalThis.process?.version?.startsWith('v2')
5
- ? ['gzip', 'deflate', 'br', 'zstd']
6
- : ['gzip', 'deflate', 'deflate-raw', 'br'];
5
+ static supportedFormats = getSupportedFormats();
7
6
  constructor(compressionFormat) {
8
7
  switch (compressionFormat) {
9
8
  case 'x-gzip':
package/esm/utils.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { once } from 'node:events';
2
+ import zlib from 'node:zlib';
2
3
  function isHeadersInstance(obj) {
3
4
  return obj?.forEach != null;
4
5
  }
@@ -96,3 +97,13 @@ class AbortError extends Error {
96
97
  this.name = 'AbortError';
97
98
  }
98
99
  }
100
+ export function getSupportedFormats() {
101
+ const baseFormats = ['gzip', 'deflate', 'br'];
102
+ if (!globalThis.process?.versions?.node?.startsWith('2')) {
103
+ baseFormats.push('deflate-raw');
104
+ }
105
+ if (zlib.createZstdCompress != null) {
106
+ baseFormats.push('zstd');
107
+ }
108
+ return baseFormats;
109
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/node-fetch",
3
- "version": "0.8.3-alpha-20251110161950-a399c572806c26a67ae5f1b3dbb21cac7461155a",
3
+ "version": "0.8.3-alpha-20251110204347-16d19b0f9727cc130885edd3d0d9a79139ac963a",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "dependencies": {
@@ -1,4 +1,5 @@
1
1
  import { Readable, Writable } from 'node:stream';
2
+ import { PonyfillCompressionFormat } from './CompressionStream';
2
3
  export declare function getHeadersObj(headers: Headers): Record<string, string>;
3
4
  export declare function defaultHeadersSerializer(headers: Headers, onContentLength?: (value: string) => void): string[];
4
5
  export { fakePromise } from '@whatwg-node/promise-helpers';
@@ -16,3 +17,4 @@ export declare function endStream(stream: {
16
17
  end: () => void;
17
18
  }): void;
18
19
  export declare function safeWrite(chunk: any, stream: Writable): Promise<any[]> | undefined;
20
+ export declare function getSupportedFormats(): PonyfillCompressionFormat[];
@@ -1,4 +1,5 @@
1
1
  import { Readable, Writable } from 'node:stream';
2
+ import { PonyfillCompressionFormat } from './CompressionStream';
2
3
  export declare function getHeadersObj(headers: Headers): Record<string, string>;
3
4
  export declare function defaultHeadersSerializer(headers: Headers, onContentLength?: (value: string) => void): string[];
4
5
  export { fakePromise } from '@whatwg-node/promise-helpers';
@@ -16,3 +17,4 @@ export declare function endStream(stream: {
16
17
  end: () => void;
17
18
  }): void;
18
19
  export declare function safeWrite(chunk: any, stream: Writable): Promise<any[]> | undefined;
20
+ export declare function getSupportedFormats(): PonyfillCompressionFormat[];