jsrosetta

Standard library

Gzip

Node.js's zlib.gzip/unzip (promisified) compared to Go's compress/gzip, Rust's flate2, Swift's zlib via C interop, and Java's java.util.zip.

Minimum versions
Node.js ≥ 14.13.1Go ≥ 1.0Rust ≥ 1.67Swift ≥ 4.0Java ≥ 25
Verified on
Node.js 24.12.0Go 1.27.1Rust 1.98.1Swift 6.2.4Java 25.0.4.1

Node.js code is an ES module: save it as .mjs or set "type": "module" in package.json.

Node.js exposes gzip through a callback in node:zlib, so the example below uses promisify to await it. Go works directly with io.Writer/io.Reader: gzip.NewWriter wraps a buffer to compress, and gzip.NewReader reads it back to decompress. Rust has no gzip in std, so it uses the flate2 crate, following the same Read/Write model. Swift has no gzip API in either Foundation or the Compression framework (that framework only outputs zlib/LZFSE format, not an actual gzip container) — the example below calls the system's zlib directly through C interop (import zlib). Java uses the long-standing java.util.zip.GZIPOutputStream/GZIPInputStream.

Compressing and decompressing

import { gzip, unzip } from 'node:zlib'
import { promisify } from 'node:util'
 
const gzipAsync = promisify(gzip)
const unzipAsync = promisify(unzip)
 
const data = Buffer.from('hello world', 'utf-8')
 
const compressed = await gzipAsync(data)
console.log(compressed) // <Buffer 1f 8b 08 00 ...>
 
const decompressed = await unzipAsync(compressed)
console.log(decompressed.toString()) // hello world

Reference: github.com/miguelmota/golang-for-nodejs-developers#gzip