Simple wrapper for Oodle data compression/decompression using native bindings via koffi.
Supports automatic downloading for current os and architecture or passing a path to the lib manually.
AI was used to generate the README and jsdoc, code is human.
npm i oodle.js@latest-
Windows: Tested
-
Linux: Tested
-
macOS: Untested (should work)
-
NodeJS: Tested
-
Bun: Tested
-
Deno: Untested
import { Oodle } from "oodle.js";
const oodle = await Oodle.Create();
const input = Buffer.from("Hello, World!".repeat(50));
const compressed = oodle.compress({
buffer: input,
});
const decompressed = oodle.decompress(
{
buffer: compressed,
},
input.length
);
console.log(decompressed.toString());const oodle = await Oodle.Create();const oodle = await Oodle.Create("./native/oodle.dll");const oodle = await Oodle.Create(true);const compressed = oodle.compress(
{
buffer: input,
size: input.length, // optional
offset: 0, // optional
},
OodleCompressor.Kraken,
OodleCompressionLevel.Optimal
);- Returns a trimmed Buffer
- Automatically allocates output buffer using Oodle’s size estimator
- Throws
OodleErroron invalid ranges or failure
const output = oodle.decompress(
{
buffer: compressed,
size: compressed.length,
offset: 0,
},
originalSize
);{
fuzzSafe?: OodleFuzzSafe;
checkCRC?: OodleCheckCRC;
verbosity?: OodleVerbosity;
decodeThreadPhase?: OodleDecodeThreadPhase;
}const compressor = oodle.getCompressor(buffer);const max = oodle.maxCompressedSize(1024, OodleCompressor.Kraken);const size = oodle.minDecodeSize(
buffer.length,
OodleCompressor.Kraken,
false
);try {
oodle.compress({ buffer: input });
} catch (err) {
if (err instanceof OodleError) {
console.log(err.code);
}
}{
name: "OodleError",
message: string,
code: string,
isOodleError(): true
}The following properties are NOT part of the public API and should not be used directly unless you know what you're doing:
_lib_Compress_Decompress_GetAllChunksCompressor_GetDecodeBufferSize_GetCompressedBufferSizeNeeded
These are direct native bindings created via koffi and may change without notice. They also lack the abstraction provided by the wrapper.
Always use:
compress()decompress()maxCompressedSize()minDecodeSize()getCompressor()
- Compression level affects speed vs ratio
- Kraken is the default compressor (good balance)
- Buffer slicing is handled internally (
offset,sizesupported) - Native memory allocation is unsafe (
Buffer.allocUnsafe) for performance
Check typings for:
OodleCompressorOodleCompressionLevelOodleFuzzSafeOodleCheckCRCOodleVerbosityOodleDecodeThreadPhase
const oodle = await Oodle.Create();
const data = Buffer.from("example data".repeat(100));
const compressed = oodle.compress({ buffer: data });
const decompressed = oodle.decompress(
{ buffer: compressed },
data.length
);
console.log(decompressed.equals(data)); // true