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 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. # @nodelib/fs.walk
  2. > A library for efficiently walking a directory recursively.
  3. ## :bulb: Highlights
  4. * :moneybag: Returns useful information: `name`, `path`, `dirent` and `stats` (optional).
  5. * :rocket: On Node.js 10.10+ uses the mechanism without additional calls to determine the entry type for performance reasons. See [`old` and `modern` mode](https://github.com/nodelib/nodelib/blob/master/packages/fs/fs.scandir/README.md#old-and-modern-mode).
  6. * :gear: Built-in directories/files and error filtering system.
  7. * :link: Can safely work with broken symbolic links.
  8. ## Install
  9. ```console
  10. npm install @nodelib/fs.walk
  11. ```
  12. ## Usage
  13. ```ts
  14. import * as fsWalk from '@nodelib/fs.walk';
  15. fsWalk.walk('path', (error, entries) => { /* … */ });
  16. ```
  17. ## API
  18. ### .walk(path, [optionsOrSettings], callback)
  19. Reads the directory recursively and asynchronously. Requires a callback function.
  20. > :book: If you want to use the Promise API, use `util.promisify`.
  21. ```ts
  22. fsWalk.walk('path', (error, entries) => { /* … */ });
  23. fsWalk.walk('path', {}, (error, entries) => { /* … */ });
  24. fsWalk.walk('path', new fsWalk.Settings(), (error, entries) => { /* … */ });
  25. ```
  26. ### .walkStream(path, [optionsOrSettings])
  27. Reads the directory recursively and asynchronously. [Readable Stream](https://nodejs.org/dist/latest-v12.x/docs/api/stream.html#stream_readable_streams) is used as a provider.
  28. ```ts
  29. const stream = fsWalk.walkStream('path');
  30. const stream = fsWalk.walkStream('path', {});
  31. const stream = fsWalk.walkStream('path', new fsWalk.Settings());
  32. ```
  33. ### .walkSync(path, [optionsOrSettings])
  34. Reads the directory recursively and synchronously. Returns an array of entries.
  35. ```ts
  36. const entries = fsWalk.walkSync('path');
  37. const entries = fsWalk.walkSync('path', {});
  38. const entries = fsWalk.walkSync('path', new fsWalk.Settings());
  39. ```
  40. #### path
  41. * Required: `true`
  42. * Type: `string | Buffer | URL`
  43. A path to a file. If a URL is provided, it must use the `file:` protocol.
  44. #### optionsOrSettings
  45. * Required: `false`
  46. * Type: `Options | Settings`
  47. * Default: An instance of `Settings` class
  48. An [`Options`](#options) object or an instance of [`Settings`](#settings) class.
  49. > :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.
  50. ### Settings([options])
  51. A class of full settings of the package.
  52. ```ts
  53. const settings = new fsWalk.Settings({ followSymbolicLinks: true });
  54. const entries = fsWalk.walkSync('path', settings);
  55. ```
  56. ## Entry
  57. * `name` — The name of the entry (`unknown.txt`).
  58. * `path` — The path of the entry relative to call directory (`root/unknown.txt`).
  59. * `dirent` — An instance of [`fs.Dirent`](./src/types/index.ts) class.
  60. * [`stats`] — An instance of `fs.Stats` class.
  61. ## Options
  62. ### basePath
  63. * Type: `string`
  64. * Default: `undefined`
  65. By default, all paths are built relative to the root path. You can use this option to set custom root path.
  66. In the example below we read the files from the `root` directory, but in the results the root path will be `custom`.
  67. ```ts
  68. fsWalk.walkSync('root'); // → ['root/file.txt']
  69. fsWalk.walkSync('root', { basePath: 'custom' }); // → ['custom/file.txt']
  70. ```
  71. ### concurrency
  72. * Type: `number`
  73. * Default: `Infinity`
  74. The maximum number of concurrent calls to `fs.readdir`.
  75. > :book: The higher the number, the higher performance and the load on the File System. If you want to read in quiet mode, set the value to `4 * os.cpus().length` (4 is default size of [thread pool work scheduling](http://docs.libuv.org/en/v1.x/threadpool.html#thread-pool-work-scheduling)).
  76. ### deepFilter
  77. * Type: [`DeepFilterFunction`](./src/settings.ts)
  78. * Default: `undefined`
  79. A function that indicates whether the directory will be read deep or not.
  80. ```ts
  81. // Skip all directories that starts with `node_modules`
  82. const filter: DeepFilterFunction = (entry) => !entry.path.startsWith('node_modules');
  83. ```
  84. ### entryFilter
  85. * Type: [`EntryFilterFunction`](./src/settings.ts)
  86. * Default: `undefined`
  87. A function that indicates whether the entry will be included to results or not.
  88. ```ts
  89. // Exclude all `.js` files from results
  90. const filter: EntryFilterFunction = (entry) => !entry.name.endsWith('.js');
  91. ```
  92. ### errorFilter
  93. * Type: [`ErrorFilterFunction`](./src/settings.ts)
  94. * Default: `undefined`
  95. A function that allows you to skip errors that occur when reading directories.
  96. For example, you can skip `ENOENT` errors if required:
  97. ```ts
  98. // Skip all ENOENT errors
  99. const filter: ErrorFilterFunction = (error) => error.code == 'ENOENT';
  100. ```
  101. ### stats
  102. * Type: `boolean`
  103. * Default: `false`
  104. Adds an instance of `fs.Stats` class to the [`Entry`](#entry).
  105. > :book: Always use `fs.readdir` with additional `fs.lstat/fs.stat` calls to determine the entry type.
  106. ### followSymbolicLinks
  107. * Type: `boolean`
  108. * Default: `false`
  109. Follow symbolic links or not. Call `fs.stat` on symbolic link if `true`.
  110. ### `throwErrorOnBrokenSymbolicLink`
  111. * Type: `boolean`
  112. * Default: `true`
  113. Throw an error when symbolic link is broken if `true` or safely return `lstat` call if `false`.
  114. ### `pathSegmentSeparator`
  115. * Type: `string`
  116. * Default: `path.sep`
  117. 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.
  118. ### `fs`
  119. * Type: `FileSystemAdapter`
  120. * Default: A default FS methods
  121. 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.
  122. ```ts
  123. interface FileSystemAdapter {
  124. lstat: typeof fs.lstat;
  125. stat: typeof fs.stat;
  126. lstatSync: typeof fs.lstatSync;
  127. statSync: typeof fs.statSync;
  128. readdir: typeof fs.readdir;
  129. readdirSync: typeof fs.readdirSync;
  130. }
  131. const settings = new fsWalk.Settings({
  132. fs: { lstat: fakeLstat }
  133. });
  134. ```
  135. ## Changelog
  136. See the [Releases section of our GitHub project](https://github.com/nodelib/nodelib/releases) for changelog for each release version.
  137. ## License
  138. This software is released under the terms of the MIT license.