07-zip.agi 999 B

1234567891011121314151617181920212223242526
  1. /*---
  2. title: Zip and unzip
  3. group: Files
  4. summary: ziplib: pack a folder, inspect the archive and extract it again.
  5. ---*/
  6. requirelib("filelib");
  7. requirelib("ziplib");
  8. ziplib.createZipFile("user:/Documents", "tmp:/documents.zip");
  9. console.log("Valid zip: " + ziplib.isValidZipFile("tmp:/documents.zip"));
  10. console.log("Type: " + ziplib.getCompressFileType("tmp:/documents.zip"));
  11. // listZipFileContents returns the archive as a tree (a JSON string).
  12. var tree = JSON.parse(ziplib.listZipFileContents("tmp:/documents.zip"));
  13. // Pack two files into a .tar.gz; the type follows the extension.
  14. ziplib.createAnyZipFile(["user:/Documents/notes.md", "user:/Documents/scores.csv"], "tmp:/two.tar.gz");
  15. ziplib.extractZipFile("tmp:/documents.zip", "tmp:/unzipped");
  16. sendJSONResp({
  17. archive: filelib.filesize("tmp:/documents.zip") + " bytes",
  18. topLevel: Object.keys(tree.children || {}),
  19. extracted: filelib.walk("tmp:/unzipped", "file"),
  20. tarGz: filelib.filesize("tmp:/two.tar.gz") + " bytes"
  21. });