{"_id":"@asyncvoid/share-fd","_rev":"2-1b25ac0aa26650fdb7dd50e23da2bf2b","name":"@asyncvoid/share-fd","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"@asyncvoid/share-fd","version":"1.0.0","keywords":["memfd_create","Rust","shm_open","NamedPipe"],"author":{"name":"AsyncVoid"},"license":"MIT","_id":"@asyncvoid/share-fd@1.0.0","maintainers":[{"name":"asyncvoid1","email":"asyncvoid@gmail.com"}],"homepage":"https://github.com/AsyncVoid/share-fd#readme","bugs":{"url":"https://github.com/AsyncVoid/share-fd/issues"},"ava":{"timeout":"2m","extensions":{"ts":"module"},"nodeArguments":["--import","@oxc-node/core/register"],"workerThreads":false,"environmentVariables":{"OXC_TSCONFIG_PATH":"./__test__/tsconfig.json"}},"dist":{"shasum":"e4fab586ceae50b8c074d18b5f0b0dd6082ff8f2","tarball":"https://registry.npmjs.org/@asyncvoid/share-fd/-/share-fd-1.0.0.tgz","fileCount":3,"integrity":"sha512-ISIqIeQmFCaUggZ3Ek6a+mPdhQxGMaeAqsX0zvKoJMzRqeKSGYU2gXR3U4FHr+AcON9R8oD+XV/mX5si7JWxNA==","signatures":[{"sig":"MEYCIQCVLYAL3cy6TZrr06XQTS2Q0j6PDzMzSAq5mZXVdccesAIhANUk4BHbz8KYBf/UtNoEIXIXbuSGzisVdV1y4MZQVYXI","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":9553},"main":"index.js","napi":{"targets":["x86_64-pc-windows-msvc","x86_64-apple-darwin","x86_64-unknown-linux-gnu","x86_64-unknown-linux-musl","aarch64-apple-darwin","aarch64-unknown-linux-gnu","aarch64-unknown-linux-musl","aarch64-pc-windows-msvc"],"binaryName":"share-fd"},"engines":{"node":">= 12.22.0 < 13 || >= 14.17.0 < 15 || >= 15.12.0 < 16 || >= 16.0.0"},"gitHead":"b9fdb26383ccf2da9d5264152e58f4218d85176e","scripts":{"lint":"oxlint .","test":"ava","bench":"node --import @oxc-node/core/register benchmark/bench.ts","build":"napi build --platform --release -s","format":"run-p format:prettier format:rs format:toml","prepare":"husky","version":"napi version","artifacts":"napi artifacts","format:rs":"cargo fmt","preversion":"napi build --platform && git add .","build:debug":"napi build --platform","format:toml":"taplo format","prepublishOnly":"napi prepublish -t npm","format:prettier":"prettier . -w"},"_npmUser":{"name":"asyncvoid1","email":"asyncvoid@gmail.com"},"prettier":{"semi":false,"printWidth":120,"arrowParens":"always","singleQuote":true,"trailingComma":"all"},"repository":{"url":"git+ssh://git@github.com/AsyncVoid/share-fd.git","type":"git"},"_npmVersion":"11.6.2","description":"Allows sharing of data between processes using file descriptors or named pipes","directories":{},"lint-staged":{"*.toml":["taplo format"],"*.@(js|ts|tsx)":["oxlint --fix"],"*.@(js|ts|tsx|yml|yaml|md|json)":["prettier --write"]},"_nodeVersion":"24.12.0","publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"_hasShrinkwrap":false,"packageManager":"yarn@4.12.0","devDependencies":{"ava":"^6.4.1","chalk":"^5.6.2","husky":"^9.1.7","oxlint":"^1.14.0","prettier":"^3.6.2","tinybench":"^6.0.0","@taplo/cli":"^0.7.0","typescript":"^5.9.2","@types/node":"^25.0.8","lint-staged":"^16.1.6","@emnapi/core":"^1.5.0","@napi-rs/cli":"^3.2.0","npm-run-all2":"^8.0.4","@oxc-node/core":"^0.0.35","@emnapi/runtime":"^1.5.0","@tybys/wasm-util":"^0.10.0"},"optionalDependencies":{"@asyncvoid/share-fd-darwin-x64":"1.0.0","@asyncvoid/share-fd-darwin-arm64":"1.0.0","@asyncvoid/share-fd-linux-x64-gnu":"1.0.0","@asyncvoid/share-fd-linux-x64-musl":"1.0.0","@asyncvoid/share-fd-win32-x64-msvc":"1.0.0","@asyncvoid/share-fd-linux-arm64-gnu":"1.0.0","@asyncvoid/share-fd-linux-arm64-musl":"1.0.0","@asyncvoid/share-fd-win32-arm64-msvc":"1.0.0"},"_npmOperationalInternal":{"tmp":"tmp/share-fd_1.0.0_1768470790371_0.5847440272648601","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"@asyncvoid/share-fd","version":"1.0.2","description":"Allows sharing of data between processes using file descriptors or named pipes","main":"index.js","author":{"name":"AsyncVoid"},"repository":{"type":"git","url":"git+ssh://git@github.com/AsyncVoid/share-fd.git"},"license":"MIT","keywords":["memfd_create","Rust","shm_open","NamedPipe"],"napi":{"binaryName":"share-fd","targets":["x86_64-pc-windows-msvc","x86_64-apple-darwin","x86_64-unknown-linux-gnu","x86_64-unknown-linux-musl","aarch64-apple-darwin","aarch64-unknown-linux-gnu","aarch64-unknown-linux-musl","aarch64-pc-windows-msvc"]},"engines":{"node":">= 12.22.0 < 13 || >= 14.17.0 < 15 || >= 15.12.0 < 16 || >= 16.0.0"},"publishConfig":{"registry":"https://registry.npmjs.org/","access":"public"},"scripts":{"artifacts":"napi artifacts","bench":"node --import @oxc-node/core/register benchmark/bench.ts","build":"napi build --platform --release -s","build:debug":"napi build --platform","format":"run-p format:prettier format:rs format:toml","format:prettier":"prettier . -w","format:toml":"taplo format","format:rs":"cargo fmt","lint":"oxlint .","prepublishOnly":"napi prepublish -t npm","test":"ava","preversion":"napi build --platform && git add .","version":"napi version","prepare":"husky"},"devDependencies":{"@emnapi/core":"^1.5.0","@emnapi/runtime":"^1.5.0","@napi-rs/cli":"^3.2.0","@oxc-node/core":"^0.0.35","@taplo/cli":"^0.7.0","@tybys/wasm-util":"^0.10.0","@types/node":"^25.0.8","ava":"^6.4.1","chalk":"^5.6.2","husky":"^9.1.7","lint-staged":"^16.1.6","npm-run-all2":"^8.0.4","oxlint":"^1.14.0","prettier":"^3.6.2","tinybench":"^6.0.0","typescript":"^5.9.2"},"lint-staged":{"*.@(js|ts|tsx)":["oxlint --fix"],"*.@(js|ts|tsx|yml|yaml|md|json)":["prettier --write"],"*.toml":["taplo format"]},"ava":{"extensions":{"ts":"module"},"timeout":"2m","workerThreads":false,"environmentVariables":{"OXC_TSCONFIG_PATH":"./__test__/tsconfig.json"},"nodeArguments":["--import","@oxc-node/core/register"]},"prettier":{"printWidth":120,"semi":false,"trailingComma":"all","singleQuote":true,"arrowParens":"always"},"packageManager":"yarn@4.12.0","optionalDependencies":{"@asyncvoid/share-fd-win32-x64-msvc":"1.0.2","@asyncvoid/share-fd-darwin-x64":"1.0.2","@asyncvoid/share-fd-linux-x64-gnu":"1.0.2","@asyncvoid/share-fd-linux-x64-musl":"1.0.2","@asyncvoid/share-fd-darwin-arm64":"1.0.2","@asyncvoid/share-fd-linux-arm64-gnu":"1.0.2","@asyncvoid/share-fd-linux-arm64-musl":"1.0.2","@asyncvoid/share-fd-win32-arm64-msvc":"1.0.2"},"gitHead":"e86780e20fd5c2204aafbdbd9d9392c7603beac7","types":"./index.d.ts","_id":"@asyncvoid/share-fd@1.0.2","bugs":{"url":"https://github.com/AsyncVoid/share-fd/issues"},"homepage":"https://github.com/AsyncVoid/share-fd#readme","_nodeVersion":"24.12.0","_npmVersion":"11.6.2","dist":{"integrity":"sha512-9egOJoAloKmD0l/9jfjM7BS5Y2ATIccHMjEwoE4RcYxrwkig6ZQfRUL+B+ZLcq/aeKFrqAHuzaoMK0OKrUGNWg==","shasum":"dc1a5492d9b7e65b8838d86cd67005397b70255e","tarball":"https://registry.npmjs.org/@asyncvoid/share-fd/-/share-fd-1.0.2.tgz","fileCount":5,"unpackedSize":35425,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCICIDTarkqj24QYHSQ/O/VGBP2Wz/r15lDRLR6aLeJ/jfAiAEvn31BmTk300APZGBN440TcP4FWcDZ50liNfJYxNcGw=="}]},"_npmUser":{"name":"asyncvoid1","email":"asyncvoid@gmail.com"},"directories":{},"maintainers":[{"name":"asyncvoid1","email":"asyncvoid@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/share-fd_1.0.2_1768705362534_0.4168845155492751"},"_hasShrinkwrap":false}},"time":{"created":"2026-01-15T09:53:10.245Z","modified":"2026-01-18T03:02:42.816Z","1.0.0":"2026-01-15T09:53:10.584Z","1.0.2":"2026-01-18T03:02:42.693Z"},"bugs":{"url":"https://github.com/AsyncVoid/share-fd/issues"},"author":{"name":"AsyncVoid"},"license":"MIT","homepage":"https://github.com/AsyncVoid/share-fd#readme","keywords":["memfd_create","Rust","shm_open","NamedPipe"],"repository":{"type":"git","url":"git+ssh://git@github.com/AsyncVoid/share-fd.git"},"description":"Allows sharing of data between processes using file descriptors or named pipes","maintainers":[{"name":"asyncvoid1","email":"asyncvoid@gmail.com"}],"readme":"# `@asyncvoid/share-fd`\n\n![CI](https://github.com/AsyncVoid/share-fd/workflows/CI/badge.svg)\n\n> Cross-platform inter-process data sharing using file descriptors and named pipes.\n\n## Overview\n\n`@asyncvoid/share-fd` provides a unified API for sharing data between processes using platform-specific memory sharing mechanisms. Data is written to a file descriptor or named pipe that can be passed to child processes, allowing efficient zero-copy data transfer disguised as a file path.\n\n### Platform Support\n\n- **Linux/FreeBSD/NetBSD**: `memfd_create` (anonymous memory-backed file descriptors)\n- **macOS/Unix**: `shm_open` (POSIX shared memory)\n- **Windows**: Named Pipes\n\nThe `share()` function automatically selects the optimal method for your platform.\n\n## Installation\n\n```bash\nnpm install @asyncvoid/share-fd\n# or\nyarn add @asyncvoid/share-fd\n```\n\n## Usage\n\n### Basic Example\n\n```javascript\nimport { share } from '@asyncvoid/share-fd'\nimport { spawnSync } from 'node:child_process'\n\n// Create a pipe with your data\nconst payload = Buffer.from('hello world')\nconst pipe = share(payload)\n\n// Pass the file descriptor to a child process\nconst child = spawnSync(process.execPath, ['./child.js'], {\n  env: { ...process.env, CONFIG_PATH: '/proc/self/fd/3' },\n  stdio: ['ignore', 'pipe', 'ignore', pipe.fd],\n  encoding: 'utf8',\n})\n\nconsole.log(child.stdout) // \"hello world\"\n\n// Clean up when done\npipe.close()\n```\n\n### Child Process (child.js)\n\n```javascript\nimport fs from 'node:fs'\n\n// Read from the file descriptor passed via environment variable\nconst data = fs.readFileSync(process.env.CONFIG_PATH, 'utf-8')\nconsole.log(data)\n```\n\n### Platform-Specific APIs\n\nYou can also use platform-specific functions directly:\n\n```javascript\nimport { shareMemFD, shareSHM, shareNamedPipe } from '@asyncvoid/share-fd'\n\n// Linux/FreeBSD only - memfd_create\nif (process.platform === 'linux') {\n  const pipe = shareMemFD(Buffer.from('data'))\n  console.log(pipe.fd, pipe.name)\n  pipe.close()\n}\n\n// Unix/macOS - shm_open\nif (process.platform === 'darwin') {\n  const pipe = shareSHM(Buffer.from('data'))\n  console.log(pipe.fd, pipe.name)\n  pipe.close()\n}\n\n// Windows - Named Pipes\nif (process.platform === 'win32') {\n  const pipe = shareNamedPipe(Buffer.from('data'))\n  console.log(pipe.path)\n  pipe.close()\n}\n```\n\n## API\n\n### `share(payload: Buffer, name?: string): Pipe`\n\nCreates a platform-appropriate shared memory region with the given payload. Automatically selects:\n- `memfd_create` on Linux/FreeBSD/NetBSD\n- `shm_open` on macOS and other Unix systems\n- Named Pipes on Windows\n\n**Parameters:**\n- `payload`: Buffer containing the data to share\n- `name` (optional): Name hint for the shared resource\n\n**Returns:** `Pipe` object with platform-specific properties\n\n### `shareMemFD(payload: Buffer, name?: string): Pipe`\n\nLinux/FreeBSD/NetBSD only. Creates an anonymous memory-backed file descriptor using `memfd_create`.\n\n### `shareSHM(payload: Buffer, name?: string): Pipe`\n\nUnix/macOS. Creates a POSIX shared memory object using `shm_open`.\n\n### `shareNamedPipe(payload: Buffer, name?: string): Pipe`\n\nWindows only. Creates a named pipe for inter-process communication.\n\n### Pipe Object\n\n**Unix/Linux (`shareMemFD`, `shareSHM`):**\n- `fd: number` - File descriptor that can be passed to child processes\n- `name: string` - Name of the shared resource\n- `close(): void` - Closes the file descriptor\n\n**Windows (`shareNamedPipe`):**\n- `path: string` - Named pipe path (e.g., `\\\\.\\pipe\\share-<ulid>`)\n- `close(): void` - Signals the pipe to stop accepting connections\n\n### Low-Level APIs\n\n```javascript\nimport { memfd_create, shm_open, set_cloexec } from '@asyncvoid/share-fd'\n\n// Create a memfd (Linux only)\nconst fd = memfd_create('myname', 0)\n\n// Create shared memory (Unix)\nconst fd = shm_open('myshm', O_CREAT | O_RDWR, 0o600)\n\n// Control close-on-exec flag (Unix)\nset_cloexec(fd, true)\n```\n\n## Development\n\n### Requirements\n\n- Rust (latest stable)\n- Node.js 12.22.0+ / 14.17.0+ / 15.12.0+ / 16.0.0+\n- yarn 1.x\n\n### Build\n\n```bash\nyarn install\nyarn build\n```\n\nThis will generate platform-specific native binaries (`.node` files).\n\n### Test\n\n```bash\nyarn test\n```\n\nRuns the test suite using [ava](https://github.com/avajs/ava).\n\n### Benchmark\n\n```bash\nyarn bench\n```\n\nRuns performance benchmarks comparing different sharing methods.\n\n## CI/CD\n\nWith GitHub Actions, each commit and pull request is automatically built and tested across:\n- **Node versions**: 20, 22\n- **Platforms**: Linux (x64, ARM64), macOS (x64, ARM64), Windows (x64, ARM64)\n- **Variants**: GNU libc, musl libc\n\nPre-built binaries are published as platform-specific optional dependencies, ensuring users don't need a Rust toolchain installed.\n\n## How It Works\n\nThis package leverages platform-specific APIs to create memory regions that can be accessed as file paths:\n\n1. **Data is written** to a file descriptor or named pipe\n2. **The descriptor is passed** to a child process via `stdio` array\n3. **Child process reads** from the descriptor using standard file I/O\n4. **No disk I/O** occurs - data stays in memory\n\nThis is particularly useful for:\n- Passing configuration to child processes\n- Sharing large data structures without serialization overhead\n- Avoiding command-line argument length limits\n- Secure data transfer (no temporary files on disk)\n\n## License\n\nMIT\n","readmeFilename":"README.md"}