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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. # tar-fs
  2. filesystem bindings for [tar-stream](https://github.com/mafintosh/tar-stream).
  3. ```
  4. npm install tar-fs
  5. ```
  6. [![build status](https://secure.travis-ci.org/mafintosh/tar-fs.png)](http://travis-ci.org/mafintosh/tar-fs)
  7. ## Usage
  8. tar-fs allows you to pack directories into tarballs and extract tarballs into directories.
  9. It doesn't gunzip for you, so if you want to extract a `.tar.gz` with this you'll need to use something like [gunzip-maybe](https://github.com/mafintosh/gunzip-maybe) in addition to this.
  10. ``` js
  11. var tar = require('tar-fs')
  12. var fs = require('fs')
  13. // packing a directory
  14. tar.pack('./my-directory').pipe(fs.createWriteStream('my-tarball.tar'))
  15. // extracting a directory
  16. fs.createReadStream('my-other-tarball.tar').pipe(tar.extract('./my-other-directory'))
  17. ```
  18. To ignore various files when packing or extracting add a ignore function to the options. `ignore`
  19. is also an alias for `filter`. Additionally you get `header` if you use ignore while extracting.
  20. That way you could also filter by metadata.
  21. ``` js
  22. var pack = tar.pack('./my-directory', {
  23. ignore: function(name) {
  24. return path.extname(name) === '.bin' // ignore .bin files when packing
  25. }
  26. })
  27. var extract = tar.extract('./my-other-directory', {
  28. ignore: function(name) {
  29. return path.extname(name) === '.bin' // ignore .bin files inside the tarball when extracing
  30. }
  31. })
  32. var extractFilesDirs = tar.extract('./my-other-other-directory', {
  33. ignore: function(_, header) {
  34. // pass files & directories, ignore e.g. symlinks
  35. return header.type !== 'file' && header.type !== 'directory'
  36. }
  37. })
  38. ```
  39. You can also specify which entries to pack using the `entries` option
  40. ```js
  41. var pack = tar.pack('./my-directory', {
  42. entries: ['file1', 'subdir/file2'] // only the specific entries will be packed
  43. })
  44. ```
  45. If you want to modify the headers when packing/extracting add a map function to the options
  46. ``` js
  47. var pack = tar.pack('./my-directory', {
  48. map: function(header) {
  49. header.name = 'prefixed/'+header.name
  50. return header
  51. }
  52. })
  53. var extract = tar.extract('./my-directory', {
  54. map: function(header) {
  55. header.name = 'another-prefix/'+header.name
  56. return header
  57. }
  58. })
  59. ```
  60. Similarly you can use `mapStream` incase you wanna modify the input/output file streams
  61. ``` js
  62. var pack = tar.pack('./my-directory', {
  63. mapStream: function(fileStream, header) {
  64. // NOTE: the returned stream HAS to have the same length as the input stream.
  65. // If not make sure to update the size in the header passed in here.
  66. if (path.extname(header.name) === '.js') {
  67. return fileStream.pipe(someTransform)
  68. }
  69. return fileStream;
  70. }
  71. })
  72. var extract = tar.extract('./my-directory', {
  73. mapStream: function(fileStream, header) {
  74. if (path.extname(header.name) === '.js') {
  75. return fileStream.pipe(someTransform)
  76. }
  77. return fileStream;
  78. }
  79. })
  80. ```
  81. Set `options.fmode` and `options.dmode` to ensure that files/directories extracted have the corresponding modes
  82. ``` js
  83. var extract = tar.extract('./my-directory', {
  84. dmode: parseInt(555, 8), // all dirs should be readable
  85. fmode: parseInt(444, 8) // all files should be readable
  86. })
  87. ```
  88. It can be useful to use `dmode` and `fmode` if you are packing/unpacking tarballs between *nix/windows to ensure that all files/directories unpacked are readable.
  89. Alternatively you can set `options.readable` and/or `options.writable` to set the dmode and fmode to readable/writable.
  90. ``` js
  91. var extract = tar.extract('./my-directory', {
  92. readable: true, // all dirs and files should be readable
  93. writable: true, // all dirs and files should be writable
  94. })
  95. ```
  96. Set `options.strict` to `false` if you want to ignore errors due to unsupported entry types (like device files)
  97. To dereference symlinks (pack the contents of the symlink instead of the link itself) set `options.dereference` to `true`.
  98. ## Copy a directory
  99. Copying a directory with permissions and mtime intact is as simple as
  100. ``` js
  101. tar.pack('source-directory').pipe(tar.extract('dest-directory'))
  102. ```
  103. ## Interaction with [`tar-stream`](https://github.com/mafintosh/tar-stream)
  104. Use `finalize: false` and the `finish` hook to
  105. leave the pack stream open for further entries (see
  106. [`tar-stream#pack`](https://github.com/mafintosh/tar-stream#packing)),
  107. and use `pack` to pass an existing pack stream.
  108. ``` js
  109. var mypack = tar.pack('./my-directory', {
  110. finalize: false,
  111. finish: function(sameAsMypack) {
  112. mypack.entry({name: 'generated-file.txt'}, "hello")
  113. tar.pack('./other-directory', {
  114. pack: sameAsMypack
  115. })
  116. }
  117. })
  118. ```
  119. ## Performance
  120. Packing and extracting a 6.1 GB with 2496 directories and 2398 files yields the following results on my Macbook Air.
  121. [See the benchmark here](https://gist.github.com/mafintosh/8102201)
  122. * tar-fs: 34.261 seconds
  123. * [node-tar](https://github.com/isaacs/node-tar): 366.123 seconds (or 10x slower)
  124. ## License
  125. MIT