Bun FFI

•
239
•

Integrates native C and C++ shared libraries into Bun runtimes using high-performance foreign function interface bindings.

The Bun FFI skill equips Claude Code with expert guidance on using Bun's native Foreign Function Interface (`bun:ffi`) to bind and execute C and C++ shared libraries directly within JavaScript and TypeScript. It covers platform-agnostic dynamic library loading via `dlopen`, type mapping with `FFIType`, string encoding with null-terminators, raw pointer manipulations, struct definitions via DataViews, and bidirectional callbacks. Developers can leverage this skill to bypass Node-API overhead, tap into system-level APIs like SQLite or custom native modules, and handle low-level memory allocation safely without leaving the Bun runtime environment.

主な機能

01Precise C-to-JavaScript primitive and pointer type mappings using FFIType
02Bidirectional C callback registration and lifecycle management
03Direct memory and pointer manipulation using ArrayBuffers and DataViews
04239 GitHub stars
05Cross-platform dynamic library loading with dlopen and suffix detection
06Thread-safe architecture guidance using Web Workers for blocking native tasks

ユースケース

01Interfacing high-performance C/C++ algorithms (e.g., cryptography, image processing) within Bun services
02Migrating legacy Node.js native addons or N-API bindings to Bun's faster native FFI
03Binding existing native system libraries like SQLite, OpenSSL, or OS APIs directly in TypeScript