Registry / database / kafkajs-snappy-typescript

kafkajs-snappy-typescript

JSON →
library1.0.3jsnpmunverified

kafkajs-snappy-typescript provides a Snappy compression and decompression codec specifically designed for use with KafkaJS, offering strict TypeScript compatibility. This package serves as a type-safe alternative to `tulios/kafkajs-snappy`, aiming to integrate seamlessly into TypeScript-first KafkaJS applications. It leverages Brooooooklyn's `snappy` Node.js compression library for its core compression logic. The current stable version is 1.0.3, primarily consisting of bug fixes and rebundling efforts to ensure proper NPM publication. As a specialized codec, its release cadence is tied to necessary compatibility updates with KafkaJS or its underlying `snappy` dependency, rather than frequent feature additions. Its key differentiator is its explicit focus on strong typing for KafkaJS environments.

npm install kafkajs-snappy-typescript
INSTALL
IMPORT
SIG · KAFKAJS-SNAPPY-TYP
K
kafkajs-snappy-typescript
databasejavascriptv1.0.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

SnappyCodec
import { SnappyCodec } from 'kafkajs-snappy-typescript';
const { SnappyCodec } = require('kafkajs-snappy-typescript');
The primary export is a named class, intended for ESM usage with TypeScript. CommonJS `require` should generally be avoided in favor of ES modules.
CompressionTypes
import { CompressionTypes, CompressionCodecs } from 'kafkajs';
While this package provides the codec, KafkaJS's `CompressionTypes` and `CompressionCodecs` are external imports necessary for codec registration.

This quickstart demonstrates how to register the Snappy codec with KafkaJS and then use it to send and receive messages with Snappy compression.

import { Kafka, CompressionTypes, CompressionCodecs } from 'kafkajs'; import { SnappyCodec } from 'kafkajs-snappy-typescript'; // Register the Snappy codec with KafkaJS CompressionCodecs[CompressionTypes.Snappy] = new SnappyCodec().codec; const kafka = new Kafka({ clientId: 'my-app', brokers: ['localhost:9092'], }); const producer = kafka.producer(); const consumer = kafka.consumer({ groupId: 'test-group' }); async function run() { await producer.connect(); await consumer.connect(); await producer.send({ topic: 'test-topic', compression: CompressionTypes.Snappy, // Use Snappy compression messages: [ { value: 'Hello KafkaJS with Snappy!' }, ], }); console.log('Message sent with Snappy compression.'); await consumer.subscribe({ topic: 'test-topic', fromBeginning: true }); await consumer.run({ eachMessage: async ({ topic, partition, message }) => { console.log({ value: message.value?.toString(), headers: message.headers, }); }, }); // Disconnect after a short period for demonstration setTimeout(async () => { await producer.disconnect(); await consumer.disconnect(); console.log('Producer and consumer disconnected.'); }, 5000); } run().catch(console.error);
Debug
Known issues
gotchaThis package is a codec and must be explicitly registered with KafkaJS via `CompressionCodecs[CompressionTypes.Snappy] = new SnappyCodec().codec;` before producing or consuming Snappy-compressed messages. Failing to register it will result in KafkaJS not knowing how to handle Snappy compression.
fix
Ensure the codec registration line is executed before any KafkaJS producer or consumer operations that involve Snappy compression.
affects: >=1.0.0
gotchaThe underlying `snappy` package, used for compression, relies on native C++ bindings. This can sometimes lead to compilation issues during `npm install` on certain environments or architectures if build tools (like `node-gyp` dependencies) are not correctly set up. Check the `snappy` package documentation for specific build requirements.
fix
Refer to the official `snappy` (Brooooooklyn/snappy) package's installation instructions and ensure all necessary system-level build tools (e.g., Python, C/C++ compiler) are installed and configured for `node-gyp`.
affects: >=1.0.0
gotchaThis library is a TypeScript-focused alternative to `tulios/kafkajs-snappy`. While functionally similar, using both or mixing their import styles could lead to type conflicts or confusion.
fix
Choose one Snappy codec library for KafkaJS (either `kafkajs-snappy-typescript` or `kafkajs-snappy`) and stick with it throughout your project for consistency and to avoid potential conflicts.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Unknown compression type
The Snappy codec was not registered with KafkaJS's `CompressionCodecs` before a producer attempted to send a Snappy-compressed message or a consumer tried to decompress one.
fix
Add `CompressionCodecs[CompressionTypes.Snappy] = new SnappyCodec().codec;` to your application startup code, ensuring it runs before KafkaJS operations.
node-pre-gyp ERR! build error
The underlying `snappy` package (which uses native code) failed to compile during installation, often due to missing build tools like `python` or `make`, or incorrect compiler setup.
fix
Ensure you have the necessary build tools installed on your system. For `node-gyp`, this typically includes Python 3, `make` (or Xcode on macOS, Visual C++ Build Tools on Windows). Consult the `node-gyp` and `snappy` documentation for detailed prerequisites.
TypeError: Cannot read properties of undefined (reading 'codec')
You might be attempting to access `.codec` on `SnappyCodec` without instantiating it first, or `SnappyCodec` itself might be undefined due to an incorrect import.
fix
Ensure you are instantiating the class correctly: `new SnappyCodec().codec`. Also, verify the import path: `import { SnappyCodec } from 'kafkajs-snappy-typescript';`
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies
kafkajsrequiredThis package registers a custom compression codec with KafkaJS, requiring it to be present in the application environment.
snappyrequiredUsed as the underlying library for the Snappy compression and decompression logic.
Agent activity
30 hits · last 30 days
node
24
OpenAI (training)
2
Resources
kafkajs-snappy-typescript — npm install kafkajs-snappy-typescript · libregistry