classic-ui/scripts/helpers/save.js

24 lines
550 B
JavaScript
Raw Permalink Normal View History

import fs from 'fs'
import zlib from 'zlib'
2022-09-21 07:08:59 +03:00
export async function save(filePath) {
const directories = filePath.split('/')
const fileName = directories[directories.length - 1]
try {
2022-09-21 07:08:59 +03:00
const data = fs.readFileSync(`${filePath}`)
const payload = await 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
}
}