You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.6 KiB

4 years ago
  1. # @nodelib/fs.stat
  2. > Get the status of a file with some features.
  3. ## :bulb: Highlights
  4. Wrapper over standard methods ([`fs.lstat`](https://nodejs.org/dist/latest/docs/api/fs.html#fs_fs_lstat_path_callback), [`fs.stat`](https://nodejs.org/dist/latest/docs/api/fs.html#fs_fs_stat_path_callback)) with some features.
  5. * :beginner: Normally follows symlinks.
  6. * :gear: Can safely work with broken symlinks (returns information about symlink instead of generating an error).
  7. ## Install
  8. ```
  9. $ npm install @nodelib/fs.stat
  10. ```
  11. ## Usage
  12. ```js
  13. const fsStat = require('@nodelib/fs.stat');
  14. fsStat.stat('path').then((stat) => {
  15. console.log(stat); // => fs.Stats
  16. });
  17. ```
  18. ## API
  19. ### fsStat.stat(path, [options])
  20. Returns a [`Promise<fs.Stats>`](https://nodejs.org/dist/latest/docs/api/fs.html#fs_class_fs_stats) for provided path.
  21. ### fsStat.statSync(path, [options])
  22. Returns a [`fs.Stats`](https://nodejs.org/dist/latest/docs/api/fs.html#fs_class_fs_stats) for provided path.
  23. ### fsStat.statCallback(path, [options], callback)
  24. Returns a [`fs.Stats`](https://nodejs.org/dist/latest/docs/api/fs.html#fs_class_fs_stats) for provided path with standard callback-style.
  25. #### path
  26. * Type: `string | Buffer | URL`
  27. The `path` argument for [`fs.lstat`](https://nodejs.org/dist/latest/docs/api/fs.html#fs_fs_lstat_path_callback) or [`fs.stat`](https://nodejs.org/dist/latest/docs/api/fs.html#fs_fs_stat_path_callback) method.
  28. #### options
  29. * Type: `Object`
  30. See [options](#options-1) section for more detailed information.
  31. ## Options
  32. ### throwErrorOnBrokenSymlinks
  33. * Type: `boolean`
  34. * Default: `true`
  35. Throw an error or return information about symlink, when symlink is broken. When `false`, methods will be return lstat call for broken symlinks.
  36. ### followSymlinks
  37. * Type: `boolean`
  38. * Default: `true`
  39. By default, the methods of this package follows symlinks. If you do not want it, set this option to `false` or use the standard method [`fs.lstat`](https://nodejs.org/dist/latest/docs/api/fs.html#fs_fs_lstat_path_callback).
  40. ### fs
  41. * Type: `FileSystemAdapter`
  42. * Default: `built-in FS methods`
  43. By default, the built-in Node.js module (`fs`) is used to work with the file system. You can replace each method with your own.
  44. ```ts
  45. interface FileSystemAdapter {
  46. lstat?: typeof fs.lstat;
  47. stat?: typeof fs.stat;
  48. lstatSync?: typeof fs.lstatSync;
  49. statSync?: typeof fs.statSync;
  50. }
  51. ```
  52. ## Changelog
  53. See the [Releases section of our GitHub project](https://github.com/nodelib/nodelib/releases) for changelogs for each release version.
  54. ## License
  55. This software is released under the terms of the MIT license.