zlib for Android
v1.3.2Androidzlib 1.3.2 for React Native apps on Android, precompiled for arm64-v8a devices and the x86_64 emulator as @crossbind/port-zlib-android.
npm install @crossbind/port-zlib-android@betaInstall
The whole flow, including Expo, is in the React Native playbook.
Usage
The examples the WebAssembly page runs, as Android compiles them: the same headers and the same calls. They are checked on the WebAssembly build.
Compress and decompress a buffer
The two calls most zlib code makes: compress2 at a chosen level, and uncompress with the original size the caller kept.
1.3.2 27 78 da true
Write a .gz that remembers its file name
deflateInit2 with windowBits 15 + 16 writes gzip instead of zlib, and deflateSetHeader fills the header fields that gunzip -N restores. inflateGetHeader reads them back.
3115 B -> 747 B, starts 1f 8b readings.csv 2026-01-01T00:00:00.000Z true
Compress small messages with a preset dictionary
A short message has little to refer back to. Load earlier messages with deflateSetDictionary and inflateSetDictionary, and each new one compresses against them.
dictionary: 1195 B 59 B message: 59 B alone, 11 B with the dictionary true
Checksum data in pieces
crc32 and adler32 continue a running value across pieces, and crc32_combine and adler32_combine join the checksums of pieces computed separately.
crc32 414fa339, adler32 5bdc0fda running crc32 414fa339, combined crc32 414fa339, combined adler32 5bdc0fda
"Stream a file through gzip" writes its input with m.FS, which Android does not have; the C++ takes paths, so it works unchanged on files in the app's storage. It runs on the WebAssembly page.
What is different on Android
- The React Native plugin compiles your headers with the library inside Gradle's native build, so
npm run androidbuilds everything. - Named imports from
./native/<header>.hwork as on the web:await initNative()once, then call the classes. - There is no
m.FSand no/memfs: files live in the app's own storage, and your C++ takes their paths. - No Worker and no COOP or COEP:
runtime: 'mt'uses pthreads directly.
Other platforms
- zlib overview: the apps, every platform's setup and the packages.
- zlib for WebAssembly: browsers, Node.js and edge runtimes.
- zlib for iOS: React Native apps on iOS.
- zlib for WASI: command-line programs under wasmtime.
Facts on this page come from the port manifests in the repository and from what npm served on beta when the site was built. See the Libraries guide for the full consumer flow.