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.

zip.js 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. const fs = require('fs')
  2. const path = require('path')
  3. const test = require('tape')
  4. const zip = require('../')
  5. const filePath = path.join(__dirname, 'content', 'file.txt')
  6. const tmpPath = path.join(__dirname, 'tmp')
  7. fs.mkdirSync(tmpPath, { recursive: true })
  8. test('zipSync', function (t) {
  9. const tmpFileZipPath = path.join(tmpPath, 'file.zip')
  10. zip.zipSync(filePath, tmpFileZipPath)
  11. const tmpFilePath = path.join(tmpPath, 'file.txt')
  12. fs.rmSync(tmpFilePath, { recursive: true, force: true })
  13. zip.unzipSync(tmpFileZipPath, tmpPath)
  14. const tmpFile = fs.readFileSync(tmpFilePath)
  15. const file = fs.readFileSync(filePath)
  16. t.deepEqual(tmpFile, file)
  17. t.end()
  18. })
  19. test('zip', function (t) {
  20. t.plan(4)
  21. const tmpFileZipPath = path.join(tmpPath, 'file.zip')
  22. zip.zip(filePath, tmpFileZipPath, function (err) {
  23. t.error(err)
  24. const tmpFilePath = path.join(tmpPath, 'file.txt')
  25. fs.rm(tmpFilePath, { recursive: true }, function (err) {
  26. t.error(err)
  27. zip.unzip(tmpFileZipPath, tmpPath, function (err) {
  28. t.error(err)
  29. const tmpFile = fs.readFileSync(tmpFilePath)
  30. const file = fs.readFileSync(filePath)
  31. t.deepEqual(tmpFile, file)
  32. })
  33. })
  34. })
  35. })