From @mongodb-js/zstd
@mongodb-js/zstd is a native zstd addon with two async functions. comprs also links the zstd C library, and adds synchronous calls, streams, dictionaries, multithreaded compression and a browser build.
import { compress, decompress } from '@mongodb-js/zstd';const compressed = await compress(buffer, 9);const restored = await decompress(compressed);import { compress, decompress } from '@derodero24/comprs/next';const compressed = await compress(buffer, { format: 'zstd', level: 9 });const restored = await decompress(compressed, { format: 'zstd' });- Results. The unified API returns a
Uint8Array; wrap it withBuffer.from(result.buffer, result.byteOffset, result.byteLength)where aBufferis required, or callzstdCompressAsync(buffer, level)andzstdDecompressAsync(data)of the package root, which return aBuffer. - Limits. comprs stops decompressing at 256 MiB by default; pass
maxOutputSizefor more. - More.
compressSync()anddecompressSync()run on the calling thread,workerscompresses large inputs on several threads, aDictionaryspeeds up small messages, andCompressionStream('zstd')streams (see Unified API).