Registry / messaging / permessage-deflate2

permessage-deflate2

JSON →
library0.1.8jsnpmunverified

A WebSocket permessage-deflate compression extension plugin for websocket-extensions, with a threshold option to skip compressing small messages. Version 0.1.8 requires Node >=20.0.0. It implements the IETF draft for permessage-deflate compression, allowing configuration of compression level, memory level, strategy, window bits, and context takeover. The key differentiator from the original permessage-deflate is the addition of a threshold option (default 0) to avoid wasting CPU on tiny payloads.

npm install permessage-deflate2
INSTALL
IMPORT
SIG · PERMESSAGE-DEFLATE
P
permessage-deflate2
messagingjavascriptv0.1.8
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import deflate from 'permessage-deflate2'
const deflate = require('permessage-deflate2')
ESM-only package since Node >=20, no CommonJS default export.
configure
import deflate from 'permessage-deflate2'; deflate.configure({...})
const { configure } = require('permessage-deflate2')
configure is not a named export; call it on the default export.
Extensions
import { Extensions } from 'websocket-extensions'
Extensions is a named export from websocket-extensions.

Shows how to import the extension, configure it with options including threshold, and add it to websocket-extensions.

import { Extensions } from 'websocket-extensions'; import deflate from 'permessage-deflate2'; import zlib from 'zlib'; const exts = new Extensions(); exts.add( deflate.configure({ level: zlib.Z_BEST_COMPRESSION, maxWindowBits: 13, threshold: 100, }) ); // Use exts with a WebSocket client or server. // For example, with 'ws' library: new WebSocket('ws://...', { extensions: [exts] })
Debug
Known issues
breakingNode.js version requirement >=20.0.0; older versions cause runtime errors.
fix
Upgrade Node.js to 20 or later, or use the original permessage-deflate package (CJS compatible).
affects: >=0.1.0
gotchaconfigure() must be called on the default import, not a named export.
fix
Use deflate.configure({...}) after import deflate from 'permessage-deflate2'.
affects: >=0.1.0
deprecatedThe original permessage-deflate package is unmaintained; this fork adds threshold but may not track future spec changes.
fix
Monitor the original spec or consider using WebSocket libraries with built-in compression.
affects: >=0.1.0
gotchathreshold option defaults to 0, meaning all messages are compressed. Setting a positive threshold may improve performance but also may cause inconsistent behavior if both endpoints don't agree.
fix
Ensure the threshold value is chosen carefully based on message size distribution.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: deflate.configure is not a function
Using CommonJS require() or destructuring the default export incorrectly.
fix
Use ESM import: import deflate from 'permessage-deflate2'
Error [ERR_REQUIRE_ESM]: require() of ES Module not supported
Package is ESM-only and cannot be required in CommonJS projects without experimental flags.
fix
Switch to ESM (e.g., type: 'module' in package.json) or use dynamic import().
No such extension 'permessage-deflate' offered by the server
server does not support the extension, or configuration mismatch (e.g., maxWindowBits).
fix
Check server capabilities and try with default options.
Upgrade
Version history
0.1.8latest on npm
Audit
Dependencies
websocket-extensionsrequiredRequired to add the permessage-deflate extension to a WebSocket stack.
Agent activity
14 hits · last 30 days
node
12
Amazon
1
OpenAI (training)
1
Resources
permessage-deflate2 — npm install permessage-deflate2 · libregistry