https://github.com/fathyb/node-async-ioctl
Asynchronous `ioctl` for Node.js
https://github.com/fathyb/node-async-ioctl
Last synced: 24 days ago
JSON representation
Asynchronous `ioctl` for Node.js
- Host: GitHub
- URL: https://github.com/fathyb/node-async-ioctl
- Owner: fathyb
- Created: 2022-10-20T08:57:34.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-10-22T07:41:45.000Z (almost 4 years ago)
- Last Synced: 2026-04-08T04:07:13.095Z (4 months ago)
- Language: C++
- Size: 33.2 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# node-async-ioctl
Asynchronous `ioctl` for Node.js. Used for [`node-nbd-client`](https://github.com/fathyb/node-nbd-client), UNIX-only.
## Usage
- `ioctl(fd: number | bigint, request: number | bigint, value: number | bigint | Buffer): Promise`
- meant for `ioctl` calls returning immediately. Uses the libuv thread pool.
- `ioctl.batch(batch: [fd: number | bigint, request: number | bigint, value: number | bigint | Buffer][]): Promise`
- same as `ioctl(fd, request, value)` except requests can be submitted in batches.
- `ioctl.blocking(fd: number | bigint, request: number | bigint, value: number | bigint | Buffer): Promise`
- meant for `ioctl` calls blocking until something happens. Uses a dedicated thread so more memory and higher latency.
```js
import { open } from 'fs'
import { ioctl } from 'async-ioctl'
// Get number of rows for current terminal
const rows = await ioctl(process.stdout.fd, 0x2000ab00)
async function getBlockDeviceSize(path: string) {
const device = await open(path)
const buffer = Buffer.alloc(8)
await ioctl(device.fd, 0x2000ab00, buffer)
return buffer
}
// Buffer argument
const result = await ioctl(device.fd, 0x2000ab00, Buffer.from('test'))
// Buffer argument
const result = await ioctl(device.fd, 0x2000ab00, BigInt('13343554'))
```