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