github, 也支持py
https://github.com/google/brotli
测试代码, 零配置的时候
const fs = require('fs')
const brotli = require('brotli')
function test(path) {
let s = fs.readFileSync(path,)
console.log(s.length)
let st = +new Date()
let compressed = brotli.compress(s)
// console.log(compressed)
let ed = +new Date()
console.log(compressed.length, compressed.length / s.length, ed - st)
st = +new Date()
let raw = brotli.decompress(compressed)
ed = +new Date()
console.log(raw.length, ed - st)
// console.log(Buffer.from(raw).toString('utf8'))
}
// 3.5M
let big = "D:/data/高考成绩/高考爬虫/json/school.json"
// 2k
let small = "D:/data/高考成绩/高考爬虫/json/province.json"
test(big)
test(small)
测试结果
3425144
242835 0.0708977491165335 17231
3425144 84
1372
287 0.20918367346938777 6
1372 30
对比pako , 压缩率很好, 但是速度稍慢
自定义配置
let compressed = brotli.compress(s,{
mode: 0, // 0 = generic, 1 = text, 2 = font (WOFF2)
quality: 6, // 0 - 11
lgwin: 22 // window size
})
有点nb啊, 直接压缩率和速度都上去了, 解压速度还是稍微慢了点
3425144
327781 0.095698458225406 233
3425144 139
1372
315 0.22959183673469388 0
1372 30
来源:oschina
链接:https://my.oschina.net/ahaoboy/blog/3173857