UNPKG

fs-extender

Version:
126 lines (124 loc) 5.38 kB
/// <reference types="node" /> import * as fs from "../patch"; import { Readable } from "stream"; export declare type MoveStreamOutType = { operation: string; type: string; item: string; error?: NodeJS.ErrnoException; }; /** Options for enfsmove */ export declare type MoveOptions = { /** Overwrite existing destination items, default to false */ overwrite?: boolean; /** Overwrite only if source file is newer than destination file default `false` * this works by checking the last time the files have been modified `stat.mTime` */ overwriteNewer?: boolean; /** * This option allows to bypass the `renameSync` function in patch, because it can * stop the event loop in `win32` if the file can't be renamed for some reason */ bypassRename?: boolean; /** if a stream is passed then it's possible to check the move process with * ```js * stream.on("data",(chunk:string)=>{ * const obj:StreamOutType = JSON.parse(chunk); * }); * ``` * this doesn't work with `moveSync` */ stream?: Readable; /** Merge items at destination default `false` * If overwrite `true` will overwrite items at destination * otherwise triggers an error when a file already exists */ merge?: boolean; }; /** * Move items in the file system async * * ```js * import * as fs from "fs-extender" * fs.move(srcPath, dstPath,(err)=>{ * if(!err) { * console.log("Files moved with success"); * } * }); * ``` * * @param src - the path to the items being moved * @param dst - the destination path to where the items will be moved * @param options - options * - `overwrite` - Overwrite existing destination items, default to false * - `overwriteNewer` - Overwrite only if source file is newer than destination file default `false` * this works by checking the last time the files have been modified `stat.mTime` * - `bypassRename` - This option allows to bypass the `renameSync` function in patch, because it can * stop the event loop in `win32` if the file can't be renamed for some reason * - `stream` - if a stream is passed then it's possible to check the move process with * ```js * stream.on("data",(chunk:string)=>{ * const obj:StreamOutType = JSON.parse(chunk); * }); * ``` * Note: this doesn't work with `moveSync` * - `merge` - Merge items at destination default `false` * If overwrite `true` will overwrite items at destination * otherwise triggers an error when a file already exists * @param callback - the callback function that will be called after the list is done */ export declare function move(src: fs.PathLike, dst: fs.PathLike, options: MoveOptions | undefined, callback: (err: NodeJS.ErrnoException) => void): void; export declare function move(src: fs.PathLike, dst: fs.PathLike, callback: (err: NodeJS.ErrnoException) => void): void; export declare namespace promises { /** * Move items in the file system async * * ```js * import * as fs from "fs-extender" * await fs.promises.move(srcPath, dstPath); * console.log("Files moved with success"); * ``` * * @param src - the path to the items being moved * @param dst - the destination path to where the items will be moved * @param options - options * - `overwrite` - Overwrite existing destination items, default to false * - `overwriteNewer` - Overwrite only if source file is newer than destination file default `false` * this works by checking the last time the files have been modified `stat.mTime` * - `bypassRename` - This option allows to bypass the `renameSync` function in patch, because it can * stop the event loop in `win32` if the file can't be renamed for some reason * - `stream` - if a stream is passed then it's possible to check the move process with * ```js * stream.on("data",(chunk:string)=>{ * const obj:StreamOutType = JSON.parse(chunk); * }); * ``` * Note: this doesn't work with `moveSync` * - `merge` - Merge items at destination default `false` * If overwrite `true` will overwrite items at destination * otherwise triggers an error when a file already exists */ function move(src: fs.PathLike, dst: fs.PathLike, options?: MoveOptions): Promise<void>; } /** * Move items in the file system sync * * ```js * import * as fs from "fs-extender" * fs.moveSync(srcPath, dstPath) * console.log("Files moved with success"); * ``` * * @param src - the path to the items being moved * @param dst - the destination path to where the items will be moved * @param options - options * - `overwrite` - Overwrite existing destination items, default to false * - `overwriteNewer` - Overwrite only if source file is newer than destination file default `false` * this works by checking the last time the files have been modified `stat.mTime` * - `bypassRename` - This option allows to bypass the `renameSync` function in patch, because it can * stop the event loop in `win32` if the file can't be renamed for some reason * - `merge` - Merge items at destination default `false` * If overwrite `true` will overwrite items at destination * otherwise triggers an error when a file already exists */ export declare function moveSync(src: fs.PathLike, dst: fs.PathLike, options?: MoveOptions): void;