brotli js 压缩库

此生再无相见时 提交于 2020-02-26 03:24:10

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

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!