8889841cREADME.md000066600000006003150513535550006035 0ustar00# @nodelib/fs.stat > Get the status of a file with some features. ## :bulb: Highlights Wrapper around standard method `fs.lstat` and `fs.stat` with some features. * :beginner: Normally follows symbolic link. * :gear: Can safely work with broken symbolic link. ## Install ```console npm install @nodelib/fs.stat ``` ## Usage ```ts import * as fsStat from '@nodelib/fs.stat'; fsStat.stat('path', (error, stats) => { /* … */ }); ``` ## API ### .stat(path, [optionsOrSettings], callback) Returns an instance of `fs.Stats` class for provided path with standard callback-style. ```ts fsStat.stat('path', (error, stats) => { /* … */ }); fsStat.stat('path', {}, (error, stats) => { /* … */ }); fsStat.stat('path', new fsStat.Settings(), (error, stats) => { /* … */ }); ``` ### .statSync(path, [optionsOrSettings]) Returns an instance of `fs.Stats` class for provided path. ```ts const stats = fsStat.stat('path'); const stats = fsStat.stat('path', {}); const stats = fsStat.stat('path', new fsStat.Settings()); ``` #### path * Required: `true` * Type: `string | Buffer | URL` A path to a file. If a URL is provided, it must use the `file:` protocol. #### optionsOrSettings * Required: `false` * Type: `Options | Settings` * Default: An instance of `Settings` class An [`Options`](#options) object or an instance of [`Settings`](#settings) class. > :book: When you pass a plain object, an instance of the `Settings` class will be created automatically. If you plan to call the method frequently, use a pre-created instance of the `Settings` class. ### Settings([options]) A class of full settings of the package. ```ts const settings = new fsStat.Settings({ followSymbolicLink: false }); const stats = fsStat.stat('path', settings); ``` ## Options ### `followSymbolicLink` * Type: `boolean` * Default: `true` Follow symbolic link or not. Call `fs.stat` on symbolic link if `true`. ### `markSymbolicLink` * Type: `boolean` * Default: `false` Mark symbolic link by setting the return value of `isSymbolicLink` function to always `true` (even after `fs.stat`). > :book: Can be used if you want to know what is hidden behind a symbolic link, but still continue to know that it is a symbolic link. ### `throwErrorOnBrokenSymbolicLink` * Type: `boolean` * Default: `true` Throw an error when symbolic link is broken if `true` or safely return `lstat` call if `false`. ### `fs` * Type: [`FileSystemAdapter`](./src/adapters/fs.ts) * Default: A default FS methods By default, the built-in Node.js module (`fs`) is used to work with the file system. You can replace any method with your own. ```ts interface FileSystemAdapter { lstat?: typeof fs.lstat; stat?: typeof fs.stat; lstatSync?: typeof fs.lstatSync; statSync?: typeof fs.statSync; } const settings = new fsStat.Settings({ fs: { lstat: fakeLstat } }); ``` ## Changelog See the [Releases section of our GitHub project](https://github.com/nodelib/nodelib/releases) for changelog for each release version. ## License This software is released under the terms of the MIT license. out/index.js000066600000001731150513535550007035 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.statSync = exports.stat = exports.Settings = void 0; const async = require("./providers/async"); const sync = require("./providers/sync"); const settings_1 = require("./settings"); exports.Settings = settings_1.default; function stat(path, optionsOrSettingsOrCallback, callback) { if (typeof optionsOrSettingsOrCallback === 'function') { async.read(path, getSettings(), optionsOrSettingsOrCallback); return; } async.read(path, getSettings(optionsOrSettingsOrCallback), callback); } exports.stat = stat; function statSync(path, optionsOrSettings) { const settings = getSettings(optionsOrSettings); return sync.read(path, settings); } exports.statSync = statSync; function getSettings(settingsOrOptions = {}) { if (settingsOrOptions instanceof settings_1.default) { return settingsOrOptions; } return new settings_1.default(settingsOrOptions); } out/settings.js000066600000001270150513535550007564 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const fs = require("./adapters/fs"); class Settings { constructor(_options = {}) { this._options = _options; this.followSymbolicLink = this._getValue(this._options.followSymbolicLink, true); this.fs = fs.createFileSystemAdapter(this._options.fs); this.markSymbolicLink = this._getValue(this._options.markSymbolicLink, false); this.throwErrorOnBrokenSymbolicLink = this._getValue(this._options.throwErrorOnBrokenSymbolicLink, true); } _getValue(option, value) { return option !== null && option !== void 0 ? option : value; } } exports.default = Settings; out/settings.d.ts000066600000001006150513535550010015 0ustar00import * as fs from './adapters/fs'; export interface Options { followSymbolicLink?: boolean; fs?: Partial; markSymbolicLink?: boolean; throwErrorOnBrokenSymbolicLink?: boolean; } export default class Settings { private readonly _options; readonly followSymbolicLink: boolean; readonly fs: fs.FileSystemAdapter; readonly markSymbolicLink: boolean; readonly throwErrorOnBrokenSymbolicLink: boolean; constructor(_options?: Options); private _getValue; } out/providers/async.d.ts000066600000000422150513535550011310 0ustar00import type Settings from '../settings'; import type { ErrnoException, Stats } from '../types'; export declare type AsyncCallback = (error: ErrnoException, stats: Stats) => void; export declare function read(path: string, settings: Settings, callback: AsyncCallback): void; out/providers/sync.d.ts000066600000000227150513535550011152 0ustar00import type Settings from '../settings'; import type { Stats } from '../types'; export declare function read(path: string, settings: Settings): Stats; out/providers/sync.js000066600000001153150513535550010715 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.read = void 0; function read(path, settings) { const lstat = settings.fs.lstatSync(path); if (!lstat.isSymbolicLink() || !settings.followSymbolicLink) { return lstat; } try { const stat = settings.fs.statSync(path); if (settings.markSymbolicLink) { stat.isSymbolicLink = () => true; } return stat; } catch (error) { if (!settings.throwErrorOnBrokenSymbolicLink) { return lstat; } throw error; } } exports.read = read; out/providers/async.js000066600000002224150513535550011056 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.read = void 0; function read(path, settings, callback) { settings.fs.lstat(path, (lstatError, lstat) => { if (lstatError !== null) { callFailureCallback(callback, lstatError); return; } if (!lstat.isSymbolicLink() || !settings.followSymbolicLink) { callSuccessCallback(callback, lstat); return; } settings.fs.stat(path, (statError, stat) => { if (statError !== null) { if (settings.throwErrorOnBrokenSymbolicLink) { callFailureCallback(callback, statError); return; } callSuccessCallback(callback, lstat); return; } if (settings.markSymbolicLink) { stat.isSymbolicLink = () => true; } callSuccessCallback(callback, stat); }); }); } exports.read = read; function callFailureCallback(callback, error) { callback(error); } function callSuccessCallback(callback, result) { callback(null, result); } out/adapters/fs.js000066600000001106150513535550010135 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createFileSystemAdapter = exports.FILE_SYSTEM_ADAPTER = void 0; const fs = require("fs"); exports.FILE_SYSTEM_ADAPTER = { lstat: fs.lstat, stat: fs.stat, lstatSync: fs.lstatSync, statSync: fs.statSync }; function createFileSystemAdapter(fsMethods) { if (fsMethods === undefined) { return exports.FILE_SYSTEM_ADAPTER; } return Object.assign(Object.assign({}, exports.FILE_SYSTEM_ADAPTER), fsMethods); } exports.createFileSystemAdapter = createFileSystemAdapter; out/adapters/fs.d.ts000066600000001231150513535550010370 0ustar00/// import * as fs from 'fs'; import type { ErrnoException } from '../types'; export declare type StatAsynchronousMethod = (path: string, callback: (error: ErrnoException | null, stats: fs.Stats) => void) => void; export declare type StatSynchronousMethod = (path: string) => fs.Stats; export interface FileSystemAdapter { lstat: StatAsynchronousMethod; stat: StatAsynchronousMethod; lstatSync: StatSynchronousMethod; statSync: StatSynchronousMethod; } export declare const FILE_SYSTEM_ADAPTER: FileSystemAdapter; export declare function createFileSystemAdapter(fsMethods?: Partial): FileSystemAdapter; out/types/index.js000066600000000115150513535550010174 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); out/types/index.d.ts000066600000000240150513535550010427 0ustar00/// import type * as fs from 'fs'; export declare type Stats = fs.Stats; export declare type ErrnoException = NodeJS.ErrnoException; out/index.d.ts000066600000001445150513535550007273 0ustar00import type { FileSystemAdapter, StatAsynchronousMethod, StatSynchronousMethod } from './adapters/fs'; import * as async from './providers/async'; import Settings, { Options } from './settings'; import type { Stats } from './types'; declare type AsyncCallback = async.AsyncCallback; declare function stat(path: string, callback: AsyncCallback): void; declare function stat(path: string, optionsOrSettings: Options | Settings, callback: AsyncCallback): void; declare namespace stat { function __promisify__(path: string, optionsOrSettings?: Options | Settings): Promise; } declare function statSync(path: string, optionsOrSettings?: Options | Settings): Stats; export { Settings, stat, statSync, AsyncCallback, FileSystemAdapter, StatAsynchronousMethod, StatSynchronousMethod, Options, Stats }; LICENSE000066600000002067150513535550005571 0ustar00The MIT License (MIT) Copyright (c) Denis Malinochkin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. package.json000066600000001733150513535550007051 0ustar00{ "name": "@nodelib/fs.stat", "version": "2.0.5", "description": "Get the status of a file with some features", "license": "MIT", "repository": "https://github.com/nodelib/nodelib/tree/master/packages/fs/fs.stat", "keywords": [ "NodeLib", "fs", "FileSystem", "file system", "stat" ], "engines": { "node": ">= 8" }, "files": [ "out/**", "!out/**/*.map", "!out/**/*.spec.*" ], "main": "out/index.js", "typings": "out/index.d.ts", "scripts": { "clean": "rimraf {tsconfig.tsbuildinfo,out}", "lint": "eslint \"src/**/*.ts\" --cache", "compile": "tsc -b .", "compile:watch": "tsc -p . --watch --sourceMap", "test": "mocha \"out/**/*.spec.js\" -s 0", "build": "npm run clean && npm run compile && npm run lint && npm test", "watch": "npm run clean && npm run compile:watch" }, "devDependencies": { "@nodelib/fs.macchiato": "1.0.4" }, "gitHead": "d6a7960d5281d3dd5f8e2efba49bb552d090f562" }