From de3d54a803e078a15c109b0e68719f2e346feef5 Mon Sep 17 00:00:00 2001 From: Rob Hogan Date: Thu, 20 Nov 2025 06:00:33 -0800 Subject: [PATCH 1/2] Add Flow lib defs for Node's zlib zstd support Summary: Since 22.15, Node.js now natively supports zstd (de)compression in `zlib`. This adds the Flow typings. - Node docs: https://nodejs.org/api/zlib.html#zlibcreatezstdcompressoptions - Reference for new constants: https://github.com/nodejs/node/blob/main/deps/zstd/lib/zstd.h Changelog: [General][Internal] Monorepo Flow typings Differential Revision: D87449911 --- flow-typed/environment/node.js | 93 ++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/flow-typed/environment/node.js b/flow-typed/environment/node.js index eecaceb1f40557..ac54aab85c5671 100644 --- a/flow-typed/environment/node.js +++ b/flow-typed/environment/node.js @@ -3402,6 +3402,20 @@ type zlib$brotliOptions = { ... }; +type zlib$zstdOptions = { + flush?: number, + finishFlush?: number, + chunkSize?: number, + params?: { + [number]: boolean | number, + ... + }, + maxOutputLength?: number, + info?: boolean, + dictionary?: Buffer, + ... +}; + type zlib$syncFn = ( buffer: Buffer | $TypedArray | DataView | ArrayBuffer | string, options?: zlib$options, @@ -3579,6 +3593,79 @@ declare module 'zlib' { BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2: number, BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES: number, BROTLI_DECODER_ERROR_UNREACHABL: number, + + ZSTD_COMPRESS: number, + ZSTD_DECOMPRESS: number, + + // Default compression level for zstd streams + ZSTD_CLEVEL_DEFAULT: number, + + // Keys for zlib$zstdOptions['params'] + ZSTD_c_compressionLevel: number, + ZSTD_c_windowLog: number, + ZSTD_c_hashLog: number, + ZSTD_c_chainLog: number, + ZSTD_c_searchLog: number, + ZSTD_c_minMatch: number, + ZSTD_c_targetLength: number, + ZSTD_c_strategy: number, + ZSTD_c_enableLongDistanceMatching: number, + ZSTD_c_ldmHashLog: number, + ZSTD_c_ldmMinMatch: number, + ZSTD_c_ldmBucketSizeLog: number, + ZSTD_c_ldmHashRateLog: number, + ZSTD_c_contentSizeFlag: number, + ZSTD_c_checksumFlag: number, + ZSTD_c_dictIDFlag: number, + ZSTD_c_nbWorkers: number, + ZSTD_c_jobSize: number, + ZSTD_c_overlapLog: number, + + // Flush opereations + ZSTD_e_continue: number, + ZSTD_e_flush: number, + ZSTD_e_end: number, + + // Values for the ZSTD_c_strategy paramater + ZSTD_fast: number, + ZSTD_dfast: number, + ZSTD_greedy: number, + ZSTD_lazy: number, + ZSTD_lazy2: number, + ZSTD_btlazy2: number, + ZSTD_btopt: number, + ZSTD_btultra: number, + ZSTD_btultra2: number, + + // Error codes + ZSTD_error_no_error: number, + ZSTD_error_GENERIC: number, + ZSTD_error_prefix_unknown: number, + ZSTD_error_version_unsupported: number, + ZSTD_error_frameParameter_unsupported: number, + ZSTD_error_frameParameter_windowTooLarge: number, + ZSTD_error_corruption_detected: number, + ZSTD_error_checksum_wrong: number, + ZSTD_error_literals_headerWrong: number, + ZSTD_error_dictionary_corrupted: number, + ZSTD_error_dictionary_wrong: number, + ZSTD_error_dictionaryCreation_failed: number, + ZSTD_error_parameter_unsupported: number, + ZSTD_error_parameter_combination_unsupported: number, + ZSTD_error_parameter_outOfBound: number, + ZSTD_error_tableLog_tooLarge: number, + ZSTD_error_maxSymbolValue_tooLarge: number, + ZSTD_error_maxSymbolValue_tooSmall: number, + ZSTD_error_stabilityCondition_notRespected: number, + ZSTD_error_stage_wrong: number, + ZSTD_error_init_missing: number, + ZSTD_error_memory_allocation: number, + ZSTD_error_workSpace_tooSmall: number, + ZSTD_error_dstSize_tooSmall: number, + ZSTD_error_srcSize_wrong: number, + ZSTD_error_dstBuffer_null: number, + ZSTD_error_noForwardProgress_destFull: number, + ZSTD_error_noForwardProgress_inputEmpty: number, ... }; declare var codes: { @@ -3598,6 +3685,8 @@ declare module 'zlib' { } declare class BrotliCompress extends Zlib {} declare class BrotliDecompress extends Zlib {} + declare class ZstdCompress extends Zlib {} + declare class ZstdDecompress extends Zlib {} declare class Deflate extends Zlib {} declare class Inflate extends Zlib {} declare class Gzip extends Zlib {} @@ -3618,6 +3707,10 @@ declare module 'zlib' { declare function createGzip(options?: zlib$options): Gzip; declare function createGunzip(options?: zlib$options): Gunzip; declare function createUnzip(options?: zlib$options): Unzip; + declare function createZstdCompress(options?: zlib$zstdOptions): ZstdCompress; + declare function createZstdDecompress( + options?: zlib$zstdOptions, + ): ZstdDecompress; declare var brotliCompress: zlib$brotliAsyncFn; declare var brotliCompressSync: zlib$brotliSyncFn; declare var brotliDeompress: zlib$brotliAsyncFn; From a40eb2475acd8c819a1497c38e14e4dbbcce756f Mon Sep 17 00:00:00 2001 From: Rob Hogan Date: Thu, 20 Nov 2025 06:00:33 -0800 Subject: [PATCH 2/2] Add Flow lib defs for Node.js streams fromWeb/toWeb Summary: Since v17 (and stable since v22.17), Node.js has helper methods for converting [Node streams](https://nodejs.org/api/stream.html) to/from [Web streams](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API) (e.g., as returned by global `fetch`). This adds the Flow typings. - Node docs: https://nodejs.org/api/stream.html#streamreadablefromwebreadablestream-options Changelog: [General][Internal] Monorepo Flow typings Differential Revision: D87543561 --- flow-typed/environment/node.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/flow-typed/environment/node.js b/flow-typed/environment/node.js index ac54aab85c5671..78668cc5b8c322 100644 --- a/flow-typed/environment/node.js +++ b/flow-typed/environment/node.js @@ -2459,6 +2459,13 @@ declare class stream$Readable extends stream$Stream { options?: readableStreamOptions, ): stream$Readable; + static fromWeb( + readableStream: ReadableStream, + options?: readableStreamOptions, + ): stream$Readable; + + static toWeb(streamReadable: stream$Readable): ReadableStream; + constructor(options?: readableStreamOptions): void; destroy(error?: Error): this; isPaused(): boolean; @@ -2504,6 +2511,13 @@ type writableStreamOptions = { ... }; declare class stream$Writable extends stream$Stream { + static fromWeb( + writableStream: WritableStream, + options?: writableStreamOptions, + ): stream$Writable; + + static toWeb(streamWritable: stream$Writable): WritableStream; + constructor(options?: writableStreamOptions): void; cork(): void; destroy(error?: Error): this; @@ -2559,6 +2573,21 @@ type duplexStreamOptions = writableStreamOptions & ... }; declare class stream$Duplex extends stream$Readable mixins stream$Writable { + static fromWeb( + pair: { + readable: ReadableStream, + writable: WritableStream, + ... + }, + options?: duplexStreamOptions, + ): stream$Duplex; + + static toWeb(streamDuplex: stream$Duplex): { + readable: ReadableStream, + writable: WritableStream, + ... + }; + constructor(options?: duplexStreamOptions): void; } type transformStreamOptions = duplexStreamOptions & {