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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # Archiver
  2. A streaming interface for archive generation
  3. Visit the [API documentation](https://www.archiverjs.com/) for a list of all methods available.
  4. ## Install
  5. ```bash
  6. npm install archiver --save
  7. ```
  8. ## Quick Start
  9. ```js
  10. // require modules
  11. const fs = require('fs');
  12. const archiver = require('archiver');
  13. // create a file to stream archive data to.
  14. const output = fs.createWriteStream(__dirname + '/example.zip');
  15. const archive = archiver('zip', {
  16. zlib: { level: 9 } // Sets the compression level.
  17. });
  18. // listen for all archive data to be written
  19. // 'close' event is fired only when a file descriptor is involved
  20. output.on('close', function() {
  21. console.log(archive.pointer() + ' total bytes');
  22. console.log('archiver has been finalized and the output file descriptor has closed.');
  23. });
  24. // This event is fired when the data source is drained no matter what was the data source.
  25. // It is not part of this library but rather from the NodeJS Stream API.
  26. // @see: https://nodejs.org/api/stream.html#stream_event_end
  27. output.on('end', function() {
  28. console.log('Data has been drained');
  29. });
  30. // good practice to catch warnings (ie stat failures and other non-blocking errors)
  31. archive.on('warning', function(err) {
  32. if (err.code === 'ENOENT') {
  33. // log warning
  34. } else {
  35. // throw error
  36. throw err;
  37. }
  38. });
  39. // good practice to catch this error explicitly
  40. archive.on('error', function(err) {
  41. throw err;
  42. });
  43. // pipe archive data to the file
  44. archive.pipe(output);
  45. // append a file from stream
  46. const file1 = __dirname + '/file1.txt';
  47. archive.append(fs.createReadStream(file1), { name: 'file1.txt' });
  48. // append a file from string
  49. archive.append('string cheese!', { name: 'file2.txt' });
  50. // append a file from buffer
  51. const buffer3 = Buffer.from('buff it!');
  52. archive.append(buffer3, { name: 'file3.txt' });
  53. // append a file
  54. archive.file('file1.txt', { name: 'file4.txt' });
  55. // append files from a sub-directory and naming it `new-subdir` within the archive
  56. archive.directory('subdir/', 'new-subdir');
  57. // append files from a sub-directory, putting its contents at the root of archive
  58. archive.directory('subdir/', false);
  59. // append files from a glob pattern
  60. archive.glob('file*.txt', {cwd:__dirname});
  61. // finalize the archive (ie we are done appending files but streams have to finish yet)
  62. // 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand
  63. archive.finalize();
  64. ```
  65. ## Formats
  66. Archiver ships with out of the box support for TAR and ZIP archives.
  67. You can register additional formats with `registerFormat`.
  68. You can check if format already exists before to register a new one with `isRegisteredFormat`.
  69. _Formats will be changing in the future to implement a middleware approach._