fs-open-sync
v1.0.1
Published
Open a file
Downloads
3
Readme
fs-open-sync
Like fs.openSync()
but does not interfere with the provided pathname.
Useful to open special files like CONOUT$
, \\.\nul
, etc.
Install
npm install --save fs-open-sync
API
This module exports a single function that works like fs.openSync()
.
open(path[, flags[, mode]])
Arguments
path
{Buffer|string} The file pathname.flags
{number|string} The access mode. Defaults to'r'
.mode
{number|string} The file mode bits to be applied when a new file is created. Defaults to0o666
.
Return value
An integer representing the file descriptor.
Exceptions
Throws a RangeError
or TypeError
if an argument in not valid or an Error
if the file cannot be opened.
Example
import open from 'fs-open-sync'; // Also available as a named export.
import { fileURLToPath } from 'node:url';
import { ok } from 'node:assert';
const __filename = fileURLToPath(import.meta.url);
const fd = open(__filename);
ok(fd > 0);