2022-06-08 06:45:37 -04:00
|
|
|
import fs from 'fs'
|
2022-10-30 15:44:20 -04:00
|
|
|
import zlib from 'zlib'
|
2022-09-21 00:08:59 -04:00
|
|
|
|
2023-05-12 18:19:58 -04:00
|
|
|
export function save(filePath) {
|
2022-06-08 06:45:37 -04:00
|
|
|
try {
|
2022-09-21 00:08:59 -04:00
|
|
|
const data = fs.readFileSync(`${filePath}`)
|
|
|
|
|
2023-05-12 18:19:58 -04:00
|
|
|
const payload = zlib.deflateSync(data, {
|
2022-10-30 15:44:20 -04:00
|
|
|
level: zlib.constants.Z_BEST_COMPRESSION,
|
|
|
|
strategy: zlib.constants.Z_FILTERED
|
2022-09-21 00:08:59 -04:00
|
|
|
})
|
2022-10-30 15:44:20 -04:00
|
|
|
|
|
|
|
fs.writeFileSync(`${filePath}.gz`, payload)
|
2022-06-08 06:45:37 -04:00
|
|
|
|
|
|
|
return true
|
|
|
|
} catch (err) {
|
2022-09-21 00:08:59 -04:00
|
|
|
console.log('on save error', filePath, err.message)
|
2022-06-08 06:45:37 -04:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|