333
schangxiang@126.com
2025-09-19 18966e02fb573c7e2bb0c6426ed792b38b910940
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var fs = require('fs')
var path = require('path')
var rimraf = require('rimraf')
var test = require('tape')
var zip = require('../')
 
var filePath = path.join(__dirname, 'content', 'file.txt')
var tmpPath = path.join(__dirname, 'tmp')
 
fs.mkdirSync(tmpPath, { recursive: true })
 
test('zipSync', function (t) {
  var tmpFileZipPath = path.join(tmpPath, 'file.zip')
  zip.zipSync(filePath, tmpFileZipPath)
 
  var tmpFilePath = path.join(tmpPath, 'file.txt')
  rimraf.sync(tmpFilePath)
  zip.unzipSync(tmpFileZipPath, tmpPath)
 
  var tmpFile = fs.readFileSync(tmpFilePath)
  var file = fs.readFileSync(filePath)
 
  t.deepEqual(tmpFile, file)
  t.end()
})
 
test('zip', function (t) {
  t.plan(4)
 
  var tmpFileZipPath = path.join(tmpPath, 'file.zip')
  zip.zip(filePath, tmpFileZipPath, function (err) {
    t.error(err)
 
    var tmpFilePath = path.join(tmpPath, 'file.txt')
    rimraf(tmpFilePath, function (err) {
      t.error(err)
 
      zip.unzip(tmpFileZipPath, tmpPath, function (err) {
        t.error(err)
 
        var tmpFile = fs.readFileSync(tmpFilePath)
        var file = fs.readFileSync(filePath)
 
        t.deepEqual(tmpFile, file)
      })
    })
  })
})