UNPKG

fs-extender

Version:
242 lines (241 loc) 10.6 kB
/// <reference types="node" /> import * as fs from "../patch"; import { Readable } from "stream"; export declare type RmStreamOutType = { type: string; item: string | Buffer; error?: NodeJS.ErrnoException; }; /** Options for enfsrm */ export declare type RmOptions = { /** This options prevents accidentally removing the disc root item, default to `false` * If `true` will allow to remove all data in the drive, if no error occur */ noPreserveRoot?: boolean; /** * When `true`, exceptions will be ignored if path does not exist. Default: `false`. */ force?: boolean; /** * If an `EBUSY`, `EMFILE`, `ENFILE`, `ENOTEMPTY`, or `EPERM` error is encountered, Node.js will retry * the operation with a linear backoff wait of retryDelay milliseconds longer on each try. * This option represents the number of retries. This option is ignored if the recursive option is not true. * Default: 0. */ maxRetries?: number; /** * If `true`, perform a recursive directory removal. * In recursive mode, operations are retried on failure. Default: `false`. */ recursive?: boolean; /** * The amount of time in milliseconds to wait between retries. * This option is ignored if the recursive option is not true. Default: `100`. */ retryDelay?: number; /** if a stream is passed then it's possible to check the rm process with * ```js * stream.on("data",(chunk:string)=>{ * const obj:StreamOutType = JSON.parse(chunk); * }); * ``` * this doesn't work with `rmSync` or `emptyDirSync` */ stream?: Readable; }; export declare type EmptyDirOptions = { /** * When `true`, exceptions will be ignored if path does not exist. Default: `false`. */ force?: boolean; /** * If an `EBUSY`, `EMFILE`, `ENFILE`, `ENOTEMPTY`, or `EPERM` error is encountered, Node.js will retry * the operation with a linear backoff wait of retryDelay milliseconds longer on each try. * This option represents the number of retries. This option is ignored if the recursive option is not true. * Default: 0. */ maxRetries?: number; /** * The amount of time in milliseconds to wait between retries. * This option is ignored if the recursive option is not true. Default: `100`. */ retryDelay?: number; /** if a stream is passed then it's possible to check the rm process with * ```js * stream.on("data",(chunk:string)=>{ * const obj:StreamOutType = JSON.parse(chunk); * }); * ``` * this doesn't work with `rmSync` or `emptyDirSync` */ stream?: Readable; }; /** * Emulate rm -rf command in node * * ```js * import * as fs from "fs-extender"; import { parseBoolean } from '../util'; * fs.rm(path,(err)=>{ * if(!err) { * console.log("item removed with success."); * } * }); * ``` * * @param path - path to remove * @param options - options * - `noPreserveRoot` - This options prevents accidentally removing the disc root item, default to `false` * If `true` will allow to remove all data in the drive, if no error occur * - `force` - When `true`, exceptions will be ignored if path does not exist. Default: `false`. * - `maxRetries` - If an `EBUSY`, `EMFILE`, `ENFILE`, `ENOTEMPTY`, or `EPERM` error is encountered, Node.js will retry * the operation with a linear backoff wait of retryDelay milliseconds longer on each try. * This option represents the number of retries. This option is ignored if the recursive option is not true. * Default: 0. * - `recursive` - If `true`, perform a recursive directory removal. * In recursive mode, operations are retried on failure. Default: `false`. * - `retryDelay` - The amount of time in milliseconds to wait between retries. * This option is ignored if the recursive option is not true. Default: `100`. * - `stream` - if a stream is passed then it's possible to check the rm process with * ```js * stream.on("data",(chunk:string)=>{ * const obj:StreamOutType = JSON.parse(chunk); * }); * ``` * Note: this doesn't work with `rmSync` or `emptyDirSync` * * @param callback - function to be called when rm completes */ export declare function rm(path: fs.PathLike, options: RmOptions | undefined, callback: (err: NodeJS.ErrnoException) => void): void; export declare function rm(path: fs.PathLike, callback: (err: NodeJS.ErrnoException) => void): void; /** * Delete all items inside a directory * * ```js * import * as fs from "fs-extender"; * fs.emptyDir(path,(err)=>{ * if(!err) { * console.log("dir is empty"); * } * }); * ``` * * @param path - path to remove * @param options - options * - `force` - When `true`, exceptions will be ignored if path does not exist. Default: `false`. * - `maxRetries` - If an `EBUSY`, `EMFILE`, `ENFILE`, `ENOTEMPTY`, or `EPERM` error is encountered, Node.js will retry * the operation with a linear backoff wait of retryDelay milliseconds longer on each try. * This option represents the number of retries. Default: 0. * - `retryDelay` - The amount of time in milliseconds to wait between retries. Default: `100`. * - `stream` - if a stream is passed then it's possible to check the rm process with * ```js * stream.on("data",(chunk:string)=>{ * const obj:StreamOutType = JSON.parse(chunk); * }); * ``` * Note: this doesn't work with `rmSync` or `emptyDirSync` * * @param callback - function to be called when rm completes */ export declare function emptyDir(path: fs.PathLike, options: EmptyDirOptions | undefined, callback: (err: NodeJS.ErrnoException) => void): void; export declare function emptyDir(path: fs.PathLike, callback: (err: NodeJS.ErrnoException) => void): void; export declare namespace promises { /** * Emulate rm -rf command in node * * ```js * import * as fs from "fs-extender"; * await fs.promises.rm(path); * console.log("item removed with success."); * ``` * * @param path - path to remove * @param options - options * - `noPreserveRoot` - This options prevents accidentally removing the disc root item, default to `false` * If `true` will allow to remove all data in the drive, if no error occur * - `force` - When `true`, exceptions will be ignored if path does not exist. Default: `false`. * - `maxRetries` - If an `EBUSY`, `EMFILE`, `ENFILE`, `ENOTEMPTY`, or `EPERM` error is encountered, Node.js will retry * the operation with a linear backoff wait of retryDelay milliseconds longer on each try. * This option represents the number of retries. This option is ignored if the recursive option is not true. * Default: 0. * - `recursive` - If `true`, perform a recursive directory removal. * In recursive mode, operations are retried on failure. Default: `false`. * - `retryDelay` - The amount of time in milliseconds to wait between retries. * This option is ignored if the recursive option is not true. Default: `100`. * - `stream` - if a stream is passed then it's possible to check the rm process with * ```js * stream.on("data",(chunk:string)=>{ * const obj:StreamOutType = JSON.parse(chunk); * }); * ``` * Note: this doesn't work with `rmSync` or `emptyDirSync` * */ function rm(path: fs.PathLike, options?: RmOptions): Promise<void>; /** * Delete all items inside a directory * * ```js * import * as fs from "fs-extender"; * await fs.promises.emptyDir(path); * console.log("dir is empty"); * ``` * * @param path - path to remove * @param options - options * - `force` - When `true`, exceptions will be ignored if path does not exist. Default: `false`. * - `maxRetries` - If an `EBUSY`, `EMFILE`, `ENFILE`, `ENOTEMPTY`, or `EPERM` error is encountered, Node.js will retry * the operation with a linear backoff wait of retryDelay milliseconds longer on each try. * This option represents the number of retries. Default: 0. * - `retryDelay` - The amount of time in milliseconds to wait between retries. Default: `100`. * - `stream` - if a stream is passed then it's possible to check the rm process with * ```js * stream.on("data",(chunk:string)=>{ * const obj:StreamOutType = JSON.parse(chunk); * }); * ``` * Note: this doesn't work with `rmSync` or `emptyDirSync` */ function emptyDir(path: fs.PathLike, options?: EmptyDirOptions): Promise<void>; } /** * Delete all items inside a directory * * ```js * import * as fs from "fs-extender"; * fs.emptyDirSync(path); * console.log("dir is empty"); * ``` * * @param path - path to remove * @param options - options * - `force` - When `true`, exceptions will be ignored if path does not exist. Default: `false`. * - `maxRetries` - If an `EBUSY`, `EMFILE`, `ENFILE`, `ENOTEMPTY`, or `EPERM` error is encountered, Node.js will retry * the operation with a linear backoff wait of retryDelay milliseconds longer on each try. * This option represents the number of retries. Default: 0. * - `retryDelay` - The amount of time in milliseconds to wait between retries. Default: `100`. */ export declare function emptyDirSync(path: fs.PathLike, options?: EmptyDirOptions): void; /** * Emulate rm -rf command in node * * ```js * import * as fs from "fs-extender"; * fs.rmSync(path); * console.log("item removed with success."); * ``` * * @param path - path to remove * @param options - options * - `noPreserveRoot` - This options prevents accidentally removing the disc root item, default to `false` * If `true` will allow to remove all data in the drive, if no error occur * - `force` - When `true`, exceptions will be ignored if path does not exist. Default: `false`. * - `maxRetries` - If an `EBUSY`, `EMFILE`, `ENFILE`, `ENOTEMPTY`, or `EPERM` error is encountered, Node.js will retry * the operation with a linear backoff wait of retryDelay milliseconds longer on each try. * This option represents the number of retries. This option is ignored if the recursive option is not true. * Default: 0. * - `recursive` - If `true`, perform a recursive directory removal. * In recursive mode, operations are retried on failure. Default: `false`. * - `retryDelay` - The amount of time in milliseconds to wait between retries. * This option is ignored if the recursive option is not true. Default: `100`. */ export declare function rmSync(path: fs.PathLike, options?: RmOptions): void;