classic-ui/scripts/helpers/save.js

21 lines
440 B
JavaScript
Raw Normal View History

import fs from 'fs'
import zlib from 'zlib'
2022-09-21 07:08:59 +03:00
export function save(filePath) {
try {
2022-09-21 07:08:59 +03:00
const data = fs.readFileSync(`${filePath}`)
const payload = zlib.deflateSync(data, {
level: zlib.constants.Z_BEST_COMPRESSION,
strategy: zlib.constants.Z_FILTERED
2022-09-21 07:08:59 +03:00
})
fs.writeFileSync(`${filePath}.gz`, payload)
return true
} catch (err) {
2022-09-21 07:08:59 +03:00
console.log('on save error', filePath, err.message)
return false
}
}