UNPKG

fs-extender

Version:
109 lines (108 loc) 5.55 kB
/// <reference types="node" /> import * as fs from "../patch"; import { URL } from "url"; /** Return an array of objects with fs.PahLike and fs.Stats */ export declare type ListResultType<T> = { path: T; stats: fs.Stats; }; /** Options used by list */ export declare type ListOptions = { /** Dereference links, default is false */ dereference?: boolean; /** Ignore error's when accessing to files or directories, default is false */ ignoreAccessError?: boolean; /** the final depth to list, default is -1, will list everything */ depth?: number; /** * The BufferEncoding to use with readdir default: `utf8` * If path sent to list is a buffer this options will be set to `buffer` */ encoding?: BufferEncoding | "buffer"; }; /** @internal */ declare type _ListOptionsInternal = Required<ListOptions>; /** @internal */ export declare function getOptions(opt?: unknown): _ListOptionsInternal; /** * Obtain the list of items under a directory and sub-directories asynchronously. * Each item will be an object containing: {path: pathToItem, stat: itemStat} * * ```js * import * as fs from "fs-extender" * fs.list("c:/",(err, items)=>{ * console.log(`${items.length} found`); * }); * ``` * * @param path * @param 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: Error | null, items: Array<{path: fs.PathLike, stats: fs.Stats}>) */ export declare function list(path: fs.PathLike, options: ListOptions & { encoding: "buffer"; }, callback: (err: NodeJS.ErrnoException | null, items: ListResultType<Buffer>[]) => void): void; export declare function list(path: string | URL, options: ListOptions | undefined, callback: (err: NodeJS.ErrnoException | null, items: ListResultType<string>[]) => void): void; export declare function list(path: Buffer, options: ListOptions | undefined, callback: (err: NodeJS.ErrnoException | null, items: ListResultType<Buffer>[]) => void): void; export declare function list(path: string | URL, callback: (err: NodeJS.ErrnoException | null, items: ListResultType<string>[]) => void): void; export declare function list(path: Buffer, callback: (err: NodeJS.ErrnoException | null, items: ListResultType<Buffer>[]) => void): void; export declare function list(path: fs.PathLike, options: ListOptions | undefined, callback: (err: NodeJS.ErrnoException | null, items: ListResultType<string | Buffer>[]) => void): void; export declare function list(path: fs.PathLike, callback: (err: NodeJS.ErrnoException | null, items: ListResultType<string | Buffer>[]) => void): void; export declare namespace promises { /** * Obtain the list of items under a directory and sub-directories asynchronously. * Each item will be an object containing: {path: pathToItem, stat: itemStat} * * ```js * import * as fs from "fs-extender" * const items = fs.promises.list("c:/"); * console.log(`${items.length} found`); * ``` * * @param path * @param 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` * @return `Promise<Array<{path: fs.PathLike, stats: fs.Stats}>>` */ function list(path: fs.PathLike, options: ListOptions & { encoding: "buffer"; }): Promise<ListResultType<Buffer>[]>; function list(path: string | URL, options?: ListOptions): Promise<ListResultType<string>[]>; function list(path: Buffer, options?: ListOptions): Promise<ListResultType<Buffer>[]>; function list(path: fs.PathLike, options?: ListOptions): Promise<ListResultType<string | Buffer>[]>; } /** * Obtain the list of items under a directory and sub-directories synchronously. * Each item will be an object containing: {path: pathToItem, stat: itemStat} * * ```js * import * as fs from "fs-extender" * const items = fs.listSync("c:/"); * console.log(`${items.length} found`); * ``` * * @param path * @param 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` * @return `Array<{path: fs.PathLike, stats: fs.Stats}>` */ export declare function listSync(path: fs.PathLike, options: ListOptions & { encoding: "buffer"; }): ListResultType<Buffer>[]; export declare function listSync(path: string | URL, options?: ListOptions): ListResultType<string>[]; export declare function listSync(path: Buffer, options?: ListOptions): ListResultType<Buffer>[]; export declare function listSync(path: fs.PathLike, options?: ListOptions): ListResultType<string | Buffer>[]; export {};