optimise zip compression

This commit is contained in:
gozzy 2022-09-21 04:08:59 +00:00
parent e502259cdb
commit b277b603c9
119 changed files with 30 additions and 39 deletions

@ -83,13 +83,11 @@
"eslint-plugin-vue": "^6.0.1", "eslint-plugin-vue": "^6.0.1",
"esm": "^3.2.25", "esm": "^3.2.25",
"jest": "^24.9.0", "jest": "^24.9.0",
"node-stream-zip": "^1.15.0",
"nodemon": "^2.0.0", "nodemon": "^2.0.0",
"prettier": "^1.19.1", "prettier": "^1.19.1",
"raw-loader": "^3.1.0", "raw-loader": "^3.1.0",
"sass": "^1.49.9", "sass": "^1.49.9",
"sass-loader": "^8.0.0", "sass-loader": "^8.0.0",
"vue-jest": "^3.0.5", "vue-jest": "^3.0.5"
"zip-local": "^0.3.4"
} }
} }

@ -1,17 +1,37 @@
import fs from 'fs' import fs from 'fs'
import zipper from 'zip-local' import Jszip from 'jszip'
const compressionConfig = {
type: "nodebuffer",
compression: "DEFLATE",
compressionOptions: {
level: 9
}
}
const fileConfig = {
binary: true,
compression: "DEFLATE"
}
export async function save(filePath) {
const jszip = new Jszip()
const directories = filePath.split('/')
const fileName = directories[directories.length - 1]
export function save(fileName) {
try { try {
zipper.sync const data = fs.readFileSync(`${filePath}`)
.zip(`${fileName}`)
.compress() await jszip.file(`${fileName}`, data, fileConfig)
.save(`${fileName}.zip`) await jszip.generateNodeStream({
...compressionConfig,
streamFiles: true
})
.pipe(fs.createWriteStream(`${filePath}.zip`))
fs.unlinkSync(fileName)
return true return true
} catch (err) { } catch (err) {
console.log('on save error', fileName, err.message) console.log('on save error', filePath, err.message)
return false return false
} }
} }

Binary file not shown.

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More