system_assignation/node_modules/cross-zip/test/zip.js

48 lines
1.2 KiB
JavaScript
Raw Normal View History

2022-03-24 09:22:39 -04:00
var fs = require('fs')
var path = require('path')
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')
fs.rmdirSync(tmpFilePath, { recursive: true })
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')
fs.rmdir(tmpFilePath, { recursive: true }, 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)
})
})
})
})