fs-extender
Version: 
Extras suite for node fs module
121 lines (120 loc) • 4.5 kB
TypeScript
/// <reference types="node" />
import * as fs from "../patch";
export declare type SizeOptions = {
    /** Dereference links, default is false */
    dereference?: boolean;
    /** the final depth to list, default is -1, will list everything */
    depth?: number;
    /** Ignore error's when accessing to files or directories, default is false */
    ignoreAccessError?: boolean;
    enconding?: BufferEncoding | "buffer";
};
export declare type SizeStats = {
    totalItems: number;
    totalSize: number;
    files: number;
    filesSize: number;
    directories: number;
    links: number;
    blockDevices: number;
    fifos: number;
    sockets: number;
    characterDevices: number;
};
/**
 * Check the size of an item, if `path` is a directory then will list all the items and return their size
 *
 * ```js
 * import * as fs from "fs-extender";
 * fs.size(path,(err, sizeStats)=>{
 *  console.log(sizeStats);
 * });
 * ```
 *
 * @param path - fs.PathLike
 * @param options - options
 * - `dereference` - Dereference links, default is `false`
 * - `ignoreAccessError` - Ignore error's when accessing to files or directories, default is `false`
 * - `depth` - the final depth to list, default is `-1`, will list everything
 * - `encoding` - The `BufferEncoding` to use with readdir default: `utf8`
 *                 If path sent to find is a `buffer` this options will be set to `buffer`
 * @param callback - (err: NodeJs.ErrNoException | null, result: SizeStats)
 *
 *  - `SizeStats`
 *      -- totalItems: number;
 *      -- totalSize: number;
 *      -- files: number;
 *      -- filesSize: number;
 *      -- directories: number;
 *      -- links: number;
 *      -- blockDevices: number;
 *      -- fifos: number;
 *      -- sockets: number;
 *      -- characterDevices: number;
 */
export declare function size(path: fs.PathLike, options: SizeOptions, callback: (err: NodeJS.ErrnoException | null, stats: SizeStats) => void): void;
export declare function size(path: fs.PathLike, callback: (err: NodeJS.ErrnoException | null, stats: SizeStats) => void): void;
/**
 * Check the size of an item, if `path` is a directory then will list all the items and return their size
 *
 * ```js
 * import * as fs from "fs-extender";
 * const sizeStats = fs.sizeSync(path);
 *  console.log(sizeStats);
 * ```
 *
 * @param path - fs.PathLike
 * @param options - options
 * - `dereference` - Dereference links, default is `false`
 * - `ignoreAccessError` - Ignore error's when accessing to files or directories, default is `false`
 * - `depth` - the final depth to list, default is `-1`, will list everything
 * - `encoding` - The `BufferEncoding` to use with readdir default: `utf8`
 *                 If path sent to find is a `buffer` this options will be set to `buffer`
 * @param SizeStats
 *
 *  - `SizeStats`
 *      -- totalItems: number;
 *      -- totalSize: number;
 *      -- files: number;
 *      -- filesSize: number;
 *      -- directories: number;
 *      -- links: number;
 *      -- blockDevices: number;
 *      -- fifos: number;
 *      -- sockets: number;
 *      -- characterDevices: number;
 */
export declare function sizeSync(path: fs.PathLike, options?: SizeOptions): SizeStats;
export declare namespace promises {
    /**
     * Check the size of an item, if `path` is a directory then will list all the items and return their size
     *
     * ```js
     * import * as fs from "fs-extender";
     * const sizeStats = await fs.promises.size(path)
     *  console.log(sizeStats);
     * ```
     *
     * @param path - fs.PathLike
     * @param options - options
     * - `dereference` - Dereference links, default is `false`
     * - `ignoreAccessError` - Ignore error's when accessing to files or directories, default is `false`
     * - `depth` - the final depth to list, default is `-1`, will list everything
     * - `encoding` - The `BufferEncoding` to use with readdir default: `utf8`
     *                 If path sent to find is a `buffer` this options will be set to `buffer`
     * @param Promise<SizeStats>
     *
     *  - `SizeStats`
     *      -- totalItems: number;
     *      -- totalSize: number;
     *      -- files: number;
     *      -- filesSize: number;
     *      -- directories: number;
     *      -- links: number;
     *      -- blockDevices: number;
     *      -- fifos: number;
     *      -- sockets: number;
     *      -- characterDevices: number;
     */
    function size(path: fs.PathLike, options?: SizeOptions): Promise<SizeStats>;
}