Skip to content
This repository has been archived by the owner on May 27, 2019. It is now read-only.
/ fs-file-sync-fd Public archive

Backported version of fs.readFileSync, fs.writeFileSync, and fs.appendFileSync which accept file descriptor arguments for synchronously reading and writing to open file descriptors.

License

Notifications You must be signed in to change notification settings

kevinoid/fs-file-sync-fd

Repository files navigation

Backported fs.*FileSync Functions

Build Status: Linux Build Status: Windows Dependency Status Supported Node Version Version on NPM

Standalone version of fs.readFileSync, fs.writeFileSync, and fs.appendFileSync which accept file descriptor arguments for synchronously reading and writing to open file descriptors (a change introduced in nodejs/node@08039628, which first appeared in Node v6.0.0).

This module uses the fs module sources and tests from nodejs/node@08039628 with subsequent updates and only the changes necessary to support older versions of Node.js (e.g. replacing octal literals with decimal to support v0.12 and earlier).

When running on Node v6.0.0 or later, importing this module is equivalent to importing the fs module directly.

Introductory Example

var fs = require('fs-file-sync-fd');

var fd = fs.openSync('package.json', 'r');
var packageJson = JSON.parse(fs.readFileSync(fd, {encoding: 'utf8'}));
console.log('Package Version: ' + packageJson.version);

Installation

This package can be installed using npm, either globally or locally, by running:

npm install fs-file-sync-fd

Recipes

Read everything from stdin

var readFileSync = require('fs-file-sync-fd').readFileSync;
var stdinContent = readFileSync(0);

Append to stdout

var appendFileSync = require('fs-file-sync-fd').appendFileSync;
appendFileSync(1, 'Hello ');
appendFileSync(1, 'World\n');

API Docs

The functions in this module are documented as part of the Node.js API:

License

This package is available under the terms of the MIT License.

About

Backported version of fs.readFileSync, fs.writeFileSync, and fs.appendFileSync which accept file descriptor arguments for synchronously reading and writing to open file descriptors.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published