Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
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.

README.md 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. # @nodelib/fs.scandir
  2. > List files and directories inside the specified directory.
  3. ## :bulb: Highlights
  4. The package is aimed at obtaining information about entries in the directory.
  5. * :moneybag: Returns useful information: `name`, `path`, `dirent` and `stats` (optional).
  6. * :gear: On Node.js 10.10+ uses the mechanism without additional calls to determine the entry type. See [`old` and `modern` mode](#old-and-modern-mode).
  7. * :link: Can safely work with broken symbolic links.
  8. ## Install
  9. ```console
  10. npm install @nodelib/fs.scandir
  11. ```
  12. ## Usage
  13. ```ts
  14. import * as fsScandir from '@nodelib/fs.scandir';
  15. fsScandir.scandir('path', (error, stats) => { /* … */ });
  16. ```
  17. ## API
  18. ### .scandir(path, [optionsOrSettings], callback)
  19. Returns an array of plain objects ([`Entry`](#entry)) with information about entry for provided path with standard callback-style.
  20. ```ts
  21. fsScandir.scandir('path', (error, entries) => { /* … */ });
  22. fsScandir.scandir('path', {}, (error, entries) => { /* … */ });
  23. fsScandir.scandir('path', new fsScandir.Settings(), (error, entries) => { /* … */ });
  24. ```
  25. ### .scandirSync(path, [optionsOrSettings])
  26. Returns an array of plain objects ([`Entry`](#entry)) with information about entry for provided path.
  27. ```ts
  28. const entries = fsScandir.scandirSync('path');
  29. const entries = fsScandir.scandirSync('path', {});
  30. const entries = fsScandir.scandirSync(('path', new fsScandir.Settings());
  31. ```
  32. #### path
  33. * Required: `true`
  34. * Type: `string | Buffer | URL`
  35. A path to a file. If a URL is provided, it must use the `file:` protocol.
  36. #### optionsOrSettings
  37. * Required: `false`
  38. * Type: `Options | Settings`
  39. * Default: An instance of `Settings` class
  40. An [`Options`](#options) object or an instance of [`Settings`](#settingsoptions) class.
  41. > :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.
  42. ### Settings([options])
  43. A class of full settings of the package.
  44. ```ts
  45. const settings = new fsScandir.Settings({ followSymbolicLinks: false });
  46. const entries = fsScandir.scandirSync('path', settings);
  47. ```
  48. ## Entry
  49. * `name` — The name of the entry (`unknown.txt`).
  50. * `path` — The path of the entry relative to call directory (`root/unknown.txt`).
  51. * `dirent` — An instance of [`fs.Dirent`](./src/types/index.ts) class. On Node.js below 10.10 will be emulated by [`DirentFromStats`](./src/utils/fs.ts) class.
  52. * `stats` (optional) — An instance of `fs.Stats` class.
  53. For example, the `scandir` call for `tools` directory with one directory inside:
  54. ```ts
  55. {
  56. dirent: Dirent { name: 'typedoc', /* … */ },
  57. name: 'typedoc',
  58. path: 'tools/typedoc'
  59. }
  60. ```
  61. ## Options
  62. ### stats
  63. * Type: `boolean`
  64. * Default: `false`
  65. Adds an instance of `fs.Stats` class to the [`Entry`](#entry).
  66. > :book: Always use `fs.readdir` without the `withFileTypes` option. ??TODO??
  67. ### followSymbolicLinks
  68. * Type: `boolean`
  69. * Default: `false`
  70. Follow symbolic links or not. Call `fs.stat` on symbolic link if `true`.
  71. ### `throwErrorOnBrokenSymbolicLink`
  72. * Type: `boolean`
  73. * Default: `true`
  74. Throw an error when symbolic link is broken if `true` or safely use `lstat` call if `false`.
  75. ### `pathSegmentSeparator`
  76. * Type: `string`
  77. * Default: `path.sep`
  78. By default, this package uses the correct path separator for your OS (`\` on Windows, `/` on Unix-like systems). But you can set this option to any separator character(s) that you want to use instead.
  79. ### `fs`
  80. * Type: [`FileSystemAdapter`](./src/adapters/fs.ts)
  81. * Default: A default FS methods
  82. 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.
  83. ```ts
  84. interface FileSystemAdapter {
  85. lstat?: typeof fs.lstat;
  86. stat?: typeof fs.stat;
  87. lstatSync?: typeof fs.lstatSync;
  88. statSync?: typeof fs.statSync;
  89. readdir?: typeof fs.readdir;
  90. readdirSync?: typeof fs.readdirSync;
  91. }
  92. const settings = new fsScandir.Settings({
  93. fs: { lstat: fakeLstat }
  94. });
  95. ```
  96. ## `old` and `modern` mode
  97. This package has two modes that are used depending on the environment and parameters of use.
  98. ### old
  99. * Node.js below `10.10` or when the `stats` option is enabled
  100. When working in the old mode, the directory is read first (`fs.readdir`), then the type of entries is determined (`fs.lstat` and/or `fs.stat` for symbolic links).
  101. ### modern
  102. * Node.js 10.10+ and the `stats` option is disabled
  103. In the modern mode, reading the directory (`fs.readdir` with the `withFileTypes` option) is combined with obtaining information about its entries. An additional call for symbolic links (`fs.stat`) is still present.
  104. This mode makes fewer calls to the file system. It's faster.
  105. ## Changelog
  106. See the [Releases section of our GitHub project](https://github.com/nodelib/nodelib/releases) for changelog for each release version.
  107. ## License
  108. This software is released under the terms of the MIT license.