Ask AI
Skip to main content

Compressions

KYVE allows developers to use compression or other algorithms on the data before it's stored on the storage provider. There are already some types of compressions available. The implementations can be found here. Select the desired ID in your pool configuration to apply them to your runtime.

List of existing compressions

IDNameDescription
0No Compression-
1GZipUses GZip as a compression algorithm

Writing a custom compression

It is effortless to add custom compression. KYVE-JS provides an easy interface that needs to be extended with two functions: The compress(data: Buffer) function describes how data gets compressed, and the decompress(data: Buffer) function describes how the compressed data gets decompressed. A name and a MimeType have to be added to enrich the metadata of the implementation.

Example: GZip

import { gunzipSync, gzipSync } from "zlib";

import { ICompression } from "../../types";

export class Gzip implements ICompression {
public name = "Gzip";
public mimeType = "application/gzip";

async compress(data: Buffer) {
return gzipSync(data);
}

async decompress(data: Buffer) {
return gunzipSync(data);
}
}

Lastly, register your implementation in the factory and create a PR.