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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. write-file-atomic
  2. -----------------
  3. This is an extension for node's `fs.writeFile` that makes its operation
  4. atomic and allows you set ownership (uid/gid of the file).
  5. ### var writeFileAtomic = require('write-file-atomic')<br>writeFileAtomic(filename, data, [options], [callback])
  6. * filename **String**
  7. * data **String** | **Buffer**
  8. * options **Object** | **String**
  9. * chown **Object** default, uid & gid of existing file, if any
  10. * uid **Number**
  11. * gid **Number**
  12. * encoding **String** | **Null** default = 'utf8'
  13. * fsync **Boolean** default = true
  14. * mode **Number** default, from existing file, if any
  15. * tmpfileCreated **Function** called when the tmpfile is created
  16. * callback **Function**
  17. Atomically and asynchronously writes data to a file, replacing the file if it already
  18. exists. data can be a string or a buffer.
  19. The file is initially named `filename + "." + murmurhex(__filename, process.pid, ++invocations)`.
  20. Note that `require('worker_threads').threadId` is used in addition to `process.pid` if running inside of a worker thread.
  21. If writeFile completes successfully then, if passed the **chown** option it will change
  22. the ownership of the file. Finally it renames the file back to the filename you specified. If
  23. it encounters errors at any of these steps it will attempt to unlink the temporary file and then
  24. pass the error back to the caller.
  25. If multiple writes are concurrently issued to the same file, the write operations are put into a queue and serialized in the order they were called, using Promises. Writes to different files are still executed in parallel.
  26. If provided, the **chown** option requires both **uid** and **gid** properties or else
  27. you'll get an error. If **chown** is not specified it will default to using
  28. the owner of the previous file. To prevent chown from being ran you can
  29. also pass `false`, in which case the file will be created with the current user's credentials.
  30. If **mode** is not specified, it will default to using the permissions from
  31. an existing file, if any. Expicitly setting this to `false` remove this default, resulting
  32. in a file created with the system default permissions.
  33. If options is a String, it's assumed to be the **encoding** option. The **encoding** option is ignored if **data** is a buffer. It defaults to 'utf8'.
  34. If the **fsync** option is **false**, writeFile will skip the final fsync call.
  35. If the **tmpfileCreated** option is specified it will be called with the name of the tmpfile when created.
  36. Example:
  37. ```javascript
  38. writeFileAtomic('message.txt', 'Hello Node', {chown:{uid:100,gid:50}}, function (err) {
  39. if (err) throw err;
  40. console.log('It\'s saved!');
  41. });
  42. ```
  43. This function also supports async/await:
  44. ```javascript
  45. (async () => {
  46. try {
  47. await writeFileAtomic('message.txt', 'Hello Node', {chown:{uid:100,gid:50}});
  48. console.log('It\'s saved!');
  49. } catch (err) {
  50. console.error(err);
  51. process.exit(1);
  52. }
  53. })();
  54. ```
  55. ### var writeFileAtomicSync = require('write-file-atomic').sync<br>writeFileAtomicSync(filename, data, [options])
  56. The synchronous version of **writeFileAtomic**.