{"version":"1.0","type":"rich","title":"Using sendfile(2) with NodeJS","description":"This example demonstrates using the `sendfile(2)` system call in NodeJS to stream file contents over a TCP connection, bypassing userspace buffering for efficiency. It creates a net server that opens a file with `process.binding('fs').open` and sends data in chunks via `sendfile`, tracking the file offset across invocations. The code handles `EAGAIN` errors by listening for the `'drain'` event and manually starting the socket’s `_writeWatcher` to resume transmission, ultimately ending the connection when the file is fully sent. The file path and port are supplied as command-line arguments.","provider_name":"VizHub AI Studio","provider_url":"https://next.vizhub.com","html":"<iframe src=\"https://next.vizhub.com/viz/gist-2030200?mode=embed\" width=\"960\" height=\"500\" scrolling=\"no\" frameborder=\"1\"></iframe>","width":960,"height":500,"cache_age":3600}