nx.js
Concepts

Compression

Compressing and decompressing data streams

nx.js implements the Web Compression Streams API, which allows your application to compress and/or decompress streams of data.

Compression Modes

The supported standardized compression modes are listed in the table below:

ModeDescription
"deflate"Uses the DEFLATE algorithm in ZLIB Compressed Data Format
"deflate-raw"Uses the DEFLATE algorithm, without a header and trailing checksum
"gzip"Uses the GZIP format

Non-Standard Algorithms

The following non-standard / extension compression modes are also supported:

ModeDescription
"zstd"Uses the Zstandard format (useful for decompressing .ncz / .xcz files)

Examples

Compress data

await Switch.file("sdmc:/file.txt")
    .pipeThrough(new CompressionStream("gzip"))
    .pipeTo(Switch.file("sdmc:/file.txt.gz"));

Decompress data

await Switch.file("sdmc:/file.txt.gz")
    .pipeThrough(new DecompressionStream("gzip"))
    .pipeTo(Switch.file("sdmc:/file.txt"));

Learn more

On this page