From 863472dbbf5059e315dd46cbec3070465c89b579 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Sun, 11 Feb 2024 19:30:40 -0800 Subject: [PATCH] standard --- index.js | 32 ++++++++++++++++---------------- test/unzip.js | 34 +++++++++++++++++----------------- test/zip.js | 28 ++++++++++++++-------------- 3 files changed, 47 insertions(+), 47 deletions(-) diff --git a/index.js b/index.js index 52fb9ad..94b6142 100644 --- a/index.js +++ b/index.js @@ -1,15 +1,15 @@ /*! cross-zip. MIT License. Feross Aboukhadijeh */ module.exports = { - zip: zip, - zipSync: zipSync, - unzip: unzip, - unzipSync: unzipSync + zip, + zipSync, + unzip, + unzipSync } -var cp = require('child_process') -var fs = require('fs') -var os = require('os') -var path = require('path') +const cp = require('child_process') +const fs = require('fs') +const os = require('os') +const path = require('path') function zip (inPath, outPath, cb) { if (!cb) cb = function () {} @@ -31,7 +31,7 @@ function zip (inPath, outPath, cb) { function copyToTemp () { fs.readFile(inPath, function (err, inFile) { if (err) return cb(err) - var tmpPath = path.join(os.tmpdir(), 'cross-zip-' + Date.now()) + const tmpPath = path.join(os.tmpdir(), 'cross-zip-' + Date.now()) fs.mkdir(tmpPath, function (err) { if (err) return cb(err) fs.writeFile(path.join(tmpPath, path.basename(inPath)), inFile, function (err) { @@ -53,7 +53,7 @@ function zip (inPath, outPath, cb) { } function doZip2 () { - var opts = { + const opts = { cwd: path.dirname(inPath), maxBuffer: Infinity } @@ -66,15 +66,15 @@ function zip (inPath, outPath, cb) { function zipSync (inPath, outPath) { if (process.platform === 'win32') { if (fs.statSync(inPath).isFile()) { - var inFile = fs.readFileSync(inPath) - var tmpPath = path.join(os.tmpdir(), 'cross-zip-' + Date.now()) + const inFile = fs.readFileSync(inPath) + const tmpPath = path.join(os.tmpdir(), 'cross-zip-' + Date.now()) fs.mkdirSync(tmpPath) fs.writeFileSync(path.join(tmpPath, path.basename(inPath)), inFile) inPath = tmpPath } fs.rmdirSync(outPath, { recursive: true, maxRetries: 3 }) } - var opts = { + const opts = { cwd: path.dirname(inPath), maxBuffer: Infinity } @@ -83,7 +83,7 @@ function zipSync (inPath, outPath) { function unzip (inPath, outPath, cb) { if (!cb) cb = function () {} - var opts = { + const opts = { maxBuffer: Infinity } cp.execFile(getUnzipCommand(), getUnzipArgs(inPath, outPath), opts, function (err) { @@ -92,7 +92,7 @@ function unzip (inPath, outPath, cb) { } function unzipSync (inPath, outPath) { - var opts = { + const opts = { maxBuffer: Infinity } cp.execFileSync(getUnzipCommand(), getUnzipArgs(inPath, outPath), opts) @@ -128,7 +128,7 @@ function getZipArgs (inPath, outPath) { '-myOutPath', quotePath(outPath) ] } else { - var fileName = path.basename(inPath) + const fileName = path.basename(inPath) return ['-r', '-y', outPath, fileName] } } diff --git a/test/unzip.js b/test/unzip.js index 5abaff3..ccf997c 100644 --- a/test/unzip.js +++ b/test/unzip.js @@ -1,21 +1,21 @@ -var fs = require('fs') -var path = require('path') -var test = require('tape') -var zip = require('../') +const fs = require('fs') +const path = require('path') +const test = require('tape') +const zip = require('../') -var filePath = path.join(__dirname, 'content', 'file.txt') -var fileZipPath = path.join(__dirname, 'content', 'file.txt.zip') -var tmpPath = path.join(__dirname, 'tmp') +const filePath = path.join(__dirname, 'content', 'file.txt') +const fileZipPath = path.join(__dirname, 'content', 'file.txt.zip') +const tmpPath = path.join(__dirname, 'tmp') fs.mkdirSync(tmpPath, { recursive: true }) test('unzipSync', function (t) { - var tmpFilePath = path.join(tmpPath, 'file.txt') + const tmpFilePath = path.join(tmpPath, 'file.txt') fs.rmdirSync(tmpFilePath, { recursive: true }) zip.unzipSync(fileZipPath, tmpPath) - var tmpFile = fs.readFileSync(tmpFilePath) - var file = fs.readFileSync(filePath) + const tmpFile = fs.readFileSync(tmpFilePath) + const file = fs.readFileSync(filePath) t.deepEqual(tmpFile, file) t.end() @@ -24,15 +24,15 @@ test('unzipSync', function (t) { test('unzip', function (t) { t.plan(3) - var tmpFilePath = path.join(tmpPath, 'file.txt') + const tmpFilePath = path.join(tmpPath, 'file.txt') fs.rmdir(tmpFilePath, { recursive: true }, function (err) { t.error(err) zip.unzip(fileZipPath, tmpPath, function (err) { t.error(err) - var tmpFile = fs.readFileSync(tmpFilePath) - var file = fs.readFileSync(filePath) + const tmpFile = fs.readFileSync(tmpFilePath) + const file = fs.readFileSync(filePath) t.deepEqual(tmpFile, file) }) @@ -42,11 +42,11 @@ test('unzip', function (t) { test('unzip from a folder with a space in it', function (t) { t.plan(4) - var zipSpacePath = path.join(tmpPath, 'folder space', path.basename(fileZipPath)) + const zipSpacePath = path.join(tmpPath, 'folder space', path.basename(fileZipPath)) fs.mkdirSync(path.dirname(zipSpacePath), { recursive: true }) fs.copyFileSync(fileZipPath, zipSpacePath) - var tmpFilePath = path.join(tmpPath, 'file.txt') + const tmpFilePath = path.join(tmpPath, 'file.txt') fs.rmdir(tmpFilePath, { recursive: true }, function (err) { t.error(err) @@ -54,8 +54,8 @@ test('unzip from a folder with a space in it', function (t) { t.error(err) t.ok(fs.existsSync(tmpFilePath), 'extracted file should exist') - var tmpFile = fs.readFileSync(tmpFilePath) - var file = fs.readFileSync(filePath) + const tmpFile = fs.readFileSync(tmpFilePath) + const file = fs.readFileSync(filePath) t.deepEqual(tmpFile, file) }) diff --git a/test/zip.js b/test/zip.js index 0489bd5..bd41efb 100644 --- a/test/zip.js +++ b/test/zip.js @@ -1,23 +1,23 @@ -var fs = require('fs') -var path = require('path') -var test = require('tape') -var zip = require('../') +const fs = require('fs') +const path = require('path') +const test = require('tape') +const zip = require('../') -var filePath = path.join(__dirname, 'content', 'file.txt') -var tmpPath = path.join(__dirname, 'tmp') +const filePath = path.join(__dirname, 'content', 'file.txt') +const tmpPath = path.join(__dirname, 'tmp') fs.mkdirSync(tmpPath, { recursive: true }) test('zipSync', function (t) { - var tmpFileZipPath = path.join(tmpPath, 'file.zip') + const tmpFileZipPath = path.join(tmpPath, 'file.zip') zip.zipSync(filePath, tmpFileZipPath) - var tmpFilePath = path.join(tmpPath, 'file.txt') + const 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) + const tmpFile = fs.readFileSync(tmpFilePath) + const file = fs.readFileSync(filePath) t.deepEqual(tmpFile, file) t.end() @@ -26,19 +26,19 @@ test('zipSync', function (t) { test('zip', function (t) { t.plan(4) - var tmpFileZipPath = path.join(tmpPath, 'file.zip') + const tmpFileZipPath = path.join(tmpPath, 'file.zip') zip.zip(filePath, tmpFileZipPath, function (err) { t.error(err) - var tmpFilePath = path.join(tmpPath, 'file.txt') + const 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) + const tmpFile = fs.readFileSync(tmpFilePath) + const file = fs.readFileSync(filePath) t.deepEqual(tmpFile, file) })