zlib for macOS
v1.3.2macOSzlib 1.3.2 for native Node.js addons and Electron on macOS, precompiled for arm64 and x64, macOS 11 or later as @crossbind/port-zlib-darwin.
Install
The addons and their loader land in dist; the Node.js playbook has the whole flow.
Usage
The examples the WebAssembly page runs, as macOS 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.
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.
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.
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.
"Stream a file through gzip" writes its input with m.FS, which macOS 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 macOS
crossbind build -p darwinlinks one.nodeaddon per architecture intodist, next to a loader,dist/<name>.native.cjs, thatrequireandimportboth load. A plaincrossbind buildskips it.await initNative()once, then call the classes: calls are synchronous, and no Worker is involved.- The library is linked into the addon statically; only libraries that ship with macOS stay dynamic.
- There is no
m.FS: the C++ reads real paths, and data such asGDAL_DATAorproj.dbis copied todist/data. - The build runs on a Mac with Xcode's command line tools and needs Docker for the SWIG bridges.
worker_threadsare not supported yet.
Other platforms
- zlib overview: the apps, every platform's setup and the packages.
- zlib for WebAssembly: browsers, Node.js and edge runtimes.
- zlib for Android: React Native apps on Android.
- zlib for iOS: React Native apps on iOS.
- zlib for Linux: native Node.js addons on Linux.
- zlib for Windows: native Node.js addons on Windows.
- 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.