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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. Node.js: fs-extra
  2. =================
  3. `fs-extra` adds file system methods that aren't included in the native `fs` module and adds promise support to the `fs` methods. It also uses [`graceful-fs`](https://github.com/isaacs/node-graceful-fs) to prevent `EMFILE` errors. It should be a drop in replacement for `fs`.
  4. [![npm Package](https://img.shields.io/npm/v/fs-extra.svg)](https://www.npmjs.org/package/fs-extra)
  5. [![License](https://img.shields.io/npm/l/express.svg)](https://github.com/jprichardson/node-fs-extra/blob/master/LICENSE)
  6. [![build status](https://img.shields.io/travis/jprichardson/node-fs-extra/master.svg)](http://travis-ci.org/jprichardson/node-fs-extra)
  7. [![windows Build status](https://img.shields.io/appveyor/ci/jprichardson/node-fs-extra/master.svg?label=windows%20build)](https://ci.appveyor.com/project/jprichardson/node-fs-extra/branch/master)
  8. [![downloads per month](http://img.shields.io/npm/dm/fs-extra.svg)](https://www.npmjs.org/package/fs-extra)
  9. [![Coverage Status](https://img.shields.io/coveralls/github/jprichardson/node-fs-extra/master.svg)](https://coveralls.io/github/jprichardson/node-fs-extra)
  10. [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
  11. Why?
  12. ----
  13. I got tired of including `mkdirp`, `rimraf`, and `ncp` in most of my projects.
  14. Installation
  15. ------------
  16. npm install fs-extra
  17. Usage
  18. -----
  19. `fs-extra` is a drop in replacement for native `fs`. All methods in `fs` are attached to `fs-extra`. All `fs` methods return promises if the callback isn't passed.
  20. You don't ever need to include the original `fs` module again:
  21. ```js
  22. const fs = require('fs') // this is no longer necessary
  23. ```
  24. you can now do this:
  25. ```js
  26. const fs = require('fs-extra')
  27. ```
  28. or if you prefer to make it clear that you're using `fs-extra` and not `fs`, you may want
  29. to name your `fs` variable `fse` like so:
  30. ```js
  31. const fse = require('fs-extra')
  32. ```
  33. you can also keep both, but it's redundant:
  34. ```js
  35. const fs = require('fs')
  36. const fse = require('fs-extra')
  37. ```
  38. Sync vs Async vs Async/Await
  39. -------------
  40. Most methods are async by default. All async methods will return a promise if the callback isn't passed.
  41. Sync methods on the other hand will throw if an error occurs.
  42. Also Async/Await will throw an error if one occurs.
  43. Example:
  44. ```js
  45. const fs = require('fs-extra')
  46. // Async with promises:
  47. fs.copy('/tmp/myfile', '/tmp/mynewfile')
  48. .then(() => console.log('success!'))
  49. .catch(err => console.error(err))
  50. // Async with callbacks:
  51. fs.copy('/tmp/myfile', '/tmp/mynewfile', err => {
  52. if (err) return console.error(err)
  53. console.log('success!')
  54. })
  55. // Sync:
  56. try {
  57. fs.copySync('/tmp/myfile', '/tmp/mynewfile')
  58. console.log('success!')
  59. } catch (err) {
  60. console.error(err)
  61. }
  62. // Async/Await:
  63. async function copyFiles () {
  64. try {
  65. await fs.copy('/tmp/myfile', '/tmp/mynewfile')
  66. console.log('success!')
  67. } catch (err) {
  68. console.error(err)
  69. }
  70. }
  71. copyFiles()
  72. ```
  73. Methods
  74. -------
  75. ### Async
  76. - [copy](docs/copy.md)
  77. - [emptyDir](docs/emptyDir.md)
  78. - [ensureFile](docs/ensureFile.md)
  79. - [ensureDir](docs/ensureDir.md)
  80. - [ensureLink](docs/ensureLink.md)
  81. - [ensureSymlink](docs/ensureSymlink.md)
  82. - [mkdirp](docs/ensureDir.md)
  83. - [mkdirs](docs/ensureDir.md)
  84. - [move](docs/move.md)
  85. - [outputFile](docs/outputFile.md)
  86. - [outputJson](docs/outputJson.md)
  87. - [pathExists](docs/pathExists.md)
  88. - [readJson](docs/readJson.md)
  89. - [remove](docs/remove.md)
  90. - [writeJson](docs/writeJson.md)
  91. ### Sync
  92. - [copySync](docs/copy-sync.md)
  93. - [emptyDirSync](docs/emptyDir-sync.md)
  94. - [ensureFileSync](docs/ensureFile-sync.md)
  95. - [ensureDirSync](docs/ensureDir-sync.md)
  96. - [ensureLinkSync](docs/ensureLink-sync.md)
  97. - [ensureSymlinkSync](docs/ensureSymlink-sync.md)
  98. - [mkdirpSync](docs/ensureDir-sync.md)
  99. - [mkdirsSync](docs/ensureDir-sync.md)
  100. - [moveSync](docs/move-sync.md)
  101. - [outputFileSync](docs/outputFile-sync.md)
  102. - [outputJsonSync](docs/outputJson-sync.md)
  103. - [pathExistsSync](docs/pathExists-sync.md)
  104. - [readJsonSync](docs/readJson-sync.md)
  105. - [removeSync](docs/remove-sync.md)
  106. - [writeJsonSync](docs/writeJson-sync.md)
  107. **NOTE:** You can still use the native Node.js methods. They are promisified and copied over to `fs-extra`. See [notes on `fs.read()` & `fs.write()`](docs/fs-read-write.md)
  108. ### What happened to `walk()` and `walkSync()`?
  109. They were removed from `fs-extra` in v2.0.0. If you need the functionality, `walk` and `walkSync` are available as separate packages, [`klaw`](https://github.com/jprichardson/node-klaw) and [`klaw-sync`](https://github.com/manidlou/node-klaw-sync).
  110. Third Party
  111. -----------
  112. ### TypeScript
  113. If you like TypeScript, you can use `fs-extra` with it: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/fs-extra
  114. ### File / Directory Watching
  115. If you want to watch for changes to files or directories, then you should use [chokidar](https://github.com/paulmillr/chokidar).
  116. ### Obtain Filesystem (Devices, Partitions) Information
  117. [fs-filesystem](https://github.com/arthurintelligence/node-fs-filesystem) allows you to read the state of the filesystem of the host on which it is run. It returns information about both the devices and the partitions (volumes) of the system.
  118. ### Misc.
  119. - [fs-extra-debug](https://github.com/jdxcode/fs-extra-debug) - Send your fs-extra calls to [debug](https://npmjs.org/package/debug).
  120. - [mfs](https://github.com/cadorn/mfs) - Monitor your fs-extra calls.
  121. Hacking on fs-extra
  122. -------------------
  123. Wanna hack on `fs-extra`? Great! Your help is needed! [fs-extra is one of the most depended upon Node.js packages](http://nodei.co/npm/fs-extra.png?downloads=true&downloadRank=true&stars=true). This project
  124. uses [JavaScript Standard Style](https://github.com/feross/standard) - if the name or style choices bother you,
  125. you're gonna have to get over it :) If `standard` is good enough for `npm`, it's good enough for `fs-extra`.
  126. [![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)
  127. What's needed?
  128. - First, take a look at existing issues. Those are probably going to be where the priority lies.
  129. - More tests for edge cases. Specifically on different platforms. There can never be enough tests.
  130. - Improve test coverage. See coveralls output for more info.
  131. Note: If you make any big changes, **you should definitely file an issue for discussion first.**
  132. ### Running the Test Suite
  133. fs-extra contains hundreds of tests.
  134. - `npm run lint`: runs the linter ([standard](http://standardjs.com/))
  135. - `npm run unit`: runs the unit tests
  136. - `npm test`: runs both the linter and the tests
  137. ### Windows
  138. If you run the tests on the Windows and receive a lot of symbolic link `EPERM` permission errors, it's
  139. because on Windows you need elevated privilege to create symbolic links. You can add this to your Windows's
  140. account by following the instructions here: http://superuser.com/questions/104845/permission-to-make-symbolic-links-in-windows-7
  141. However, I didn't have much luck doing this.
  142. Since I develop on Mac OS X, I use VMWare Fusion for Windows testing. I create a shared folder that I map to a drive on Windows.
  143. I open the `Node.js command prompt` and run as `Administrator`. I then map the network drive running the following command:
  144. net use z: "\\vmware-host\Shared Folders"
  145. I can then navigate to my `fs-extra` directory and run the tests.
  146. Naming
  147. ------
  148. I put a lot of thought into the naming of these functions. Inspired by @coolaj86's request. So he deserves much of the credit for raising the issue. See discussion(s) here:
  149. * https://github.com/jprichardson/node-fs-extra/issues/2
  150. * https://github.com/flatiron/utile/issues/11
  151. * https://github.com/ryanmcgrath/wrench-js/issues/29
  152. * https://github.com/substack/node-mkdirp/issues/17
  153. First, I believe that in as many cases as possible, the [Node.js naming schemes](http://nodejs.org/api/fs.html) should be chosen. However, there are problems with the Node.js own naming schemes.
  154. For example, `fs.readFile()` and `fs.readdir()`: the **F** is capitalized in *File* and the **d** is not capitalized in *dir*. Perhaps a bit pedantic, but they should still be consistent. Also, Node.js has chosen a lot of POSIX naming schemes, which I believe is great. See: `fs.mkdir()`, `fs.rmdir()`, `fs.chown()`, etc.
  155. We have a dilemma though. How do you consistently name methods that perform the following POSIX commands: `cp`, `cp -r`, `mkdir -p`, and `rm -rf`?
  156. My perspective: when in doubt, err on the side of simplicity. A directory is just a hierarchical grouping of directories and files. Consider that for a moment. So when you want to copy it or remove it, in most cases you'll want to copy or remove all of its contents. When you want to create a directory, if the directory that it's suppose to be contained in does not exist, then in most cases you'll want to create that too.
  157. So, if you want to remove a file or a directory regardless of whether it has contents, just call `fs.remove(path)`. If you want to copy a file or a directory whether it has contents, just call `fs.copy(source, destination)`. If you want to create a directory regardless of whether its parent directories exist, just call `fs.mkdirs(path)` or `fs.mkdirp(path)`.
  158. Credit
  159. ------
  160. `fs-extra` wouldn't be possible without using the modules from the following authors:
  161. - [Isaac Shlueter](https://github.com/isaacs)
  162. - [Charlie McConnel](https://github.com/avianflu)
  163. - [James Halliday](https://github.com/substack)
  164. - [Andrew Kelley](https://github.com/andrewrk)
  165. License
  166. -------
  167. Licensed under MIT
  168. Copyright (c) 2011-2017 [JP Richardson](https://github.com/jprichardson)
  169. [1]: http://nodejs.org/docs/latest/api/fs.html
  170. [jsonfile]: https://github.com/jprichardson/node-jsonfile