iconv for macOS
v1.19macOSiconv 1.19 for native Node.js addons and Electron on macOS, precompiled for arm64 and x64, macOS 11 or later as @crossbind/port-iconv-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.
Convert between UTF-8 and a legacy encoding
What most iconv code does: iconv_open, iconv in a loop and iconv_close, strict in both directions. A last call without input ends stateful encodings such as ISO-2022-JP, which is where the closing ESC ( B comes from.
Transliterate or drop what the target cannot hold
Append //TRANSLIT to the target and iconv approximates a missing character; append //IGNORE and it drops it. The return value of iconv counts those characters. GNU libiconv transliterates the same way in every locale, so ASCII keeps accents as marks.
Decode a stream that cuts characters in two
Bytes from fetch, a WebSocket or a serial port arrive in pieces of any size, so a multibyte character can straddle two pieces. iconv stops with EINVAL at such a cut and the unfinished bytes wait for the next piece; E2BIG only means the output buffer is full.
List the encodings and check a name
iconvlist walks every encoding with its aliases and iconv_canonicalize names the canonical one, but only iconv_open proves a name works. GNU libiconv writes UTF-8 with its hyphen, and this build leaves out CP437 with the other DOS and EBCDIC code pages.
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
- iconv overview: the apps, every platform's setup and the packages.
- iconv for WebAssembly: browsers, Node.js and edge runtimes.
- iconv for Android: React Native apps on Android.
- iconv for iOS: React Native apps on iOS.
- iconv for Linux: native Node.js addons on Linux.
- iconv for Windows: native Node.js addons on Windows.
- iconv 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.