Product
Introducing Socket Optimize
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.
@types/graceful-fs
Advanced tools
@types/graceful-fs provides TypeScript type definitions for the graceful-fs package, which is a drop-in replacement for the native Node.js fs module with improvements to handle EMFILE errors (too many open files) gracefully.
Reading Files
This feature allows you to read the contents of a file asynchronously. The graceful-fs package ensures that the operation handles too many open files errors gracefully.
const fs = require('graceful-fs');
fs.readFile('example.txt', 'utf8', (err, data) => {
if (err) throw err;
console.log(data);
});
Writing Files
This feature allows you to write data to a file asynchronously. The graceful-fs package ensures that the operation handles too many open files errors gracefully.
const fs = require('graceful-fs');
fs.writeFile('example.txt', 'Hello, world!', (err) => {
if (err) throw err;
console.log('File has been saved!');
});
Appending to Files
This feature allows you to append data to a file asynchronously. The graceful-fs package ensures that the operation handles too many open files errors gracefully.
const fs = require('graceful-fs');
fs.appendFile('example.txt', 'Appending some text.', (err) => {
if (err) throw err;
console.log('Text has been appended!');
});
Deleting Files
This feature allows you to delete a file asynchronously. The graceful-fs package ensures that the operation handles too many open files errors gracefully.
const fs = require('graceful-fs');
fs.unlink('example.txt', (err) => {
if (err) throw err;
console.log('File has been deleted!');
});
fs-extra is a package that extends the native Node.js fs module with additional methods and promises support. It provides more functionality than graceful-fs, such as copying, moving, and ensuring directories and files. However, it does not specifically focus on handling too many open files errors.
node-fs is a package that provides additional file system methods for Node.js. It includes features like recursive directory creation and symbolic link support. While it offers more functionality than the native fs module, it does not specifically address too many open files errors like graceful-fs.
fs.promises is a built-in module in Node.js that provides promise-based versions of the fs module's methods. It offers a modern, promise-based API for file system operations but does not include the enhancements for handling too many open files errors that graceful-fs provides.
npm install --save @types/graceful-fs
This package contains type definitions for graceful-fs (https://github.com/isaacs/node-graceful-fs).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/graceful-fs.
// Type definitions for graceful-fs 4.1
// Project: https://github.com/isaacs/node-graceful-fs
// Definitions by: Bart van der Schoor <https://github.com/Bartvds>
// BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
export * from "fs";
/**
* Use this method to patch the global fs module (or any other fs-like module).
* NOTE: This should only ever be done at the top-level application layer, in order to delay on
* EMFILE errors from any fs-using dependencies. You should **not** do this in a library, because
* it can cause unexpected delays in other parts of the program.
* @param fsModule The reference to the fs module or an fs-like module.
*/
export function gracefulify<T>(fsModule: T): T;
These definitions were written by Bart van der Schoor, and BendingBender.
FAQs
TypeScript definitions for graceful-fs
The npm package @types/graceful-fs receives a total of 16,964,703 weekly downloads. As such, @types/graceful-fs popularity was classified as popular.
We found that @types/graceful-fs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.
Product
We're excited to announce that Socket now supports the Java programming language.
Security News
Socket detected a malicious Python package impersonating a popular browser cookie library to steal passwords, screenshots, webcam images, and Discord tokens.