UNPKG

fs-extender

Version:
80 lines (79 loc) 3.99 kB
/// <reference types="node" /> import * as fs from "../../patch"; import * as util from "../util"; /** * ensureFile - ensures file existence on file system * * ```js * import * as fs from "fs-extender" * fs.ensureFile(path,(err)=>{ * if(!err) { * console.log(`${path} is ensured in the file system.`); * } * }); * ``` * * @param path - the path to the file * @param options - used to create the file or modify it, options can be * - `data`: {string | NodeJS.ArrayBufferView} - Data to be written in the file, default: `undefined` * - `encoding` - Encoding to be used when data is string, default: `utf8` * - `dirMode` - Mode defined for the directory where file will be created, default: `undefined`, * if directory exists mode will not be altered, if diretory is created then the default system mode will be used * - `stream` - File to be created must return a stream to the user, default: `false` * - `streamOptions` - If stream option is set to true this option will hold the stream properties: * -- `flags: string | undefined` * -- `encoding: BufferEncoding | undefined` * -- `fd: number | NodeFs.promises.FileHandle | undefined` * -- `mode: number | undefined` * -- `autoClose: boolean | undefined` * -- `emitClose: boolean` - default: false * -- `start: number | undefined` * -- `highWaterMark: number | undefined` * - `flag` - flag used to create the file, default: `wx` * - `mode` - mode used to set the file mode, default: 0o777 * @param callback - `(err: Error |null, (path: fs.PathLike | stream: fs.WriteStrem))` */ export declare function ensureFile(path: fs.PathLike, options: (util.EnsureOptionsFile & { stream?: false; }) | undefined, callback: (err: NodeJS.ErrnoException | null, path?: fs.PathLike) => void): void; export declare function ensureFile(path: fs.PathLike, options: (util.EnsureOptionsFile & { stream: true; }) | undefined, callback: (err: NodeJS.ErrnoException | null, stream?: fs.WriteStream) => void): void; export declare function ensureFile(path: fs.PathLike, callback: (err: NodeJS.ErrnoException, path?: fs.PathLike) => void): void; export declare namespace promises { /** * ensureFile - ensures file existence on file system * * ```js * import * as fs from "fs-extender" * await fs.promises.ensureFile(path); * console.log(`${path} is ensured in the file system.`); * ``` * * @param path - the path to the file * @param options - used to create the file or modify it, options can be * - `data`: {string | NodeJS.ArrayBufferView} - Data to be written in the file, default: `undefined` * - `encoding` - Encoding to be used when data is string, default: `utf8` * - `dirMode` - Mode defined for the directory where file will be created, default: `undefined`, * if directory exists mode will not be altered, if diretory is created then the default system mode will be used * - `stream` - File to be created must return a stream to the user, default: `false` * - `streamOptions` - If stream option is set to true this option will hold the stream properties: * -- `flags: string | undefined` * -- `encoding: BufferEncoding | undefined` * -- `fd: number | NodeFs.promises.FileHandle | undefined` * -- `mode: number | undefined` * -- `autoClose: boolean | undefined` * -- `emitClose: boolean` - default: false * -- `start: number | undefined` * -- `highWaterMark: number | undefined` * - `flag` - flag used to create the file, default: `wx` * - `mode` - mode used to set the file mode, default: 0o777 * @return Promise<path: fs.PathLike | stream: fs.WriteStrem>` */ function ensureFile(path: fs.PathLike, options?: (util.EnsureOptionsFile & { stream?: false; }) | undefined): Promise<fs.PathLike>; function ensureFile(path: fs.PathLike, options: (util.EnsureOptionsFile & { stream: true; }) | undefined): Promise<fs.WriteStream>; }