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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. # tar-stream
  2. tar-stream is a streaming tar parser and generator and nothing else. It is streams2 and operates purely using streams which means you can easily extract/parse tarballs without ever hitting the file system.
  3. Note that you still need to gunzip your data if you have a `.tar.gz`. We recommend using [gunzip-maybe](https://github.com/mafintosh/gunzip-maybe) in conjunction with this.
  4. ```
  5. npm install tar-stream
  6. ```
  7. [![build status](https://secure.travis-ci.org/mafintosh/tar-stream.png)](http://travis-ci.org/mafintosh/tar-stream)
  8. [![License](https://img.shields.io/badge/license-MIT-blue.svg)](http://opensource.org/licenses/MIT)
  9. ## Usage
  10. tar-stream exposes two streams, [pack](https://github.com/mafintosh/tar-stream#packing) which creates tarballs and [extract](https://github.com/mafintosh/tar-stream#extracting) which extracts tarballs. To [modify an existing tarball](https://github.com/mafintosh/tar-stream#modifying-existing-tarballs) use both.
  11. It implementes USTAR with additional support for pax extended headers. It should be compatible with all popular tar distributions out there (gnutar, bsdtar etc)
  12. ## Related
  13. If you want to pack/unpack directories on the file system check out [tar-fs](https://github.com/mafintosh/tar-fs) which provides file system bindings to this module.
  14. ## Packing
  15. To create a pack stream use `tar.pack()` and call `pack.entry(header, [callback])` to add tar entries.
  16. ``` js
  17. var tar = require('tar-stream')
  18. var pack = tar.pack() // pack is a streams2 stream
  19. // add a file called my-test.txt with the content "Hello World!"
  20. pack.entry({ name: 'my-test.txt' }, 'Hello World!')
  21. // add a file called my-stream-test.txt from a stream
  22. var entry = pack.entry({ name: 'my-stream-test.txt', size: 11 }, function(err) {
  23. // the stream was added
  24. // no more entries
  25. pack.finalize()
  26. })
  27. entry.write('hello')
  28. entry.write(' ')
  29. entry.write('world')
  30. entry.end()
  31. // pipe the pack stream somewhere
  32. pack.pipe(process.stdout)
  33. ```
  34. ## Extracting
  35. To extract a stream use `tar.extract()` and listen for `extract.on('entry', (header, stream, next) )`
  36. ``` js
  37. var extract = tar.extract()
  38. extract.on('entry', function(header, stream, next) {
  39. // header is the tar header
  40. // stream is the content body (might be an empty stream)
  41. // call next when you are done with this entry
  42. stream.on('end', function() {
  43. next() // ready for next entry
  44. })
  45. stream.resume() // just auto drain the stream
  46. })
  47. extract.on('finish', function() {
  48. // all entries read
  49. })
  50. pack.pipe(extract)
  51. ```
  52. The tar archive is streamed sequentially, meaning you **must** drain each entry's stream as you get them or else the main extract stream will receive backpressure and stop reading.
  53. ## Headers
  54. The header object using in `entry` should contain the following properties.
  55. Most of these values can be found by stat'ing a file.
  56. ``` js
  57. {
  58. name: 'path/to/this/entry.txt',
  59. size: 1314, // entry size. defaults to 0
  60. mode: 0o644, // entry mode. defaults to to 0o755 for dirs and 0o644 otherwise
  61. mtime: new Date(), // last modified date for entry. defaults to now.
  62. type: 'file', // type of entry. defaults to file. can be:
  63. // file | link | symlink | directory | block-device
  64. // character-device | fifo | contiguous-file
  65. linkname: 'path', // linked file name
  66. uid: 0, // uid of entry owner. defaults to 0
  67. gid: 0, // gid of entry owner. defaults to 0
  68. uname: 'maf', // uname of entry owner. defaults to null
  69. gname: 'staff', // gname of entry owner. defaults to null
  70. devmajor: 0, // device major version. defaults to 0
  71. devminor: 0 // device minor version. defaults to 0
  72. }
  73. ```
  74. ## Modifying existing tarballs
  75. Using tar-stream it is easy to rewrite paths / change modes etc in an existing tarball.
  76. ``` js
  77. var extract = tar.extract()
  78. var pack = tar.pack()
  79. var path = require('path')
  80. extract.on('entry', function(header, stream, callback) {
  81. // let's prefix all names with 'tmp'
  82. header.name = path.join('tmp', header.name)
  83. // write the new entry to the pack stream
  84. stream.pipe(pack.entry(header, callback))
  85. })
  86. extract.on('finish', function() {
  87. // all entries done - lets finalize it
  88. pack.finalize()
  89. })
  90. // pipe the old tarball to the extractor
  91. oldTarballStream.pipe(extract)
  92. // pipe the new tarball the another stream
  93. pack.pipe(newTarballStream)
  94. ```
  95. ## Saving tarball to fs
  96. ``` js
  97. var fs = require('fs')
  98. var tar = require('tar-stream')
  99. var pack = tar.pack() // pack is a streams2 stream
  100. var path = 'YourTarBall.tar'
  101. var yourTarball = fs.createWriteStream(path)
  102. // add a file called YourFile.txt with the content "Hello World!"
  103. pack.entry({name: 'YourFile.txt'}, 'Hello World!', function (err) {
  104. if (err) throw err
  105. pack.finalize()
  106. })
  107. // pipe the pack stream to your file
  108. pack.pipe(yourTarball)
  109. yourTarball.on('close', function () {
  110. console.log(path + ' has been written')
  111. fs.stat(path, function(err, stats) {
  112. if (err) throw err
  113. console.log(stats)
  114. console.log('Got file info successfully!')
  115. })
  116. })
  117. ```
  118. ## Performance
  119. [See tar-fs for a performance comparison with node-tar](https://github.com/mafintosh/tar-fs/blob/master/README.md#performance)
  120. # License
  121. MIT