mirror of https://github.com/curbengh/hexo-yam
parent
f7b6e05180
commit
2cd5786e86
|
|
@ -266,7 +266,7 @@ minify:
|
|||
- **verbose** - Verbose output. Defaults to `false`.
|
||||
- **include** - Include files. Support [wildcard](http://www.globtester.com/) pattern(s) in a string or array.
|
||||
- **globOptions** - See [globbing](#globbing) section.
|
||||
- **level** - Compression level. Range `1-22`. Defaults to `3`, or the value of [`DEFAULT_LEVEL`](https://github.com/mongodb-js/zstd/blob/a3a08c61c9045411c8275e248498dbc583457fb5/src/lib.rs#L9)
|
||||
- **level** - Compression level. Range `1-22`. Defaults to `3`, or the value of [`ZSTD_CLEVEL_DEFAULT`](https://nodejs.org/api/zlib.html#zlib_compressor_options_1)
|
||||
|
||||
## Globbing
|
||||
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ const zlib = require('zlib')
|
|||
const { promisify } = require('util')
|
||||
const gzip = promisify(zlib.gzip)
|
||||
const br = promisify(zlib.brotliCompress)
|
||||
const zstd = promisify(zlib.zstdCompress)
|
||||
const { minify: compressXml } = require('minify-xml')
|
||||
const micromatch = require('micromatch')
|
||||
const { compress: zstd } = require('@mongodb-js/zstd')
|
||||
|
||||
const isMatch = (path = '', patterns = [], options = {}) => {
|
||||
if (path && patterns) {
|
||||
|
|
@ -240,7 +240,7 @@ function zstdFn () {
|
|||
const routeList = route.list()
|
||||
const { globOptions, include, verbose } = options
|
||||
let { level } = options
|
||||
if (typeof level !== 'number') level = undefined
|
||||
if (typeof level !== 'number') level = zlib.constants.ZSTD_CLEVEL_DEFAULT
|
||||
|
||||
return Promise.all((match(routeList, include, globOptions)).map((path) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
|
@ -250,8 +250,7 @@ function zstdFn () {
|
|||
assetPath.on('end', async () => {
|
||||
if (assetTxt.length) {
|
||||
try {
|
||||
const input = Buffer.from(assetTxt, 'utf-8')
|
||||
const result = await zstd(input, level)
|
||||
const result = await zstd(assetTxt, { params: { [zlib.constants.ZSTD_c_compressionLevel]: level } })
|
||||
if (verbose) logFn.call(this, assetTxt, result, path, 'zstd')
|
||||
resolve(route.set(path + '.zst', result))
|
||||
} catch (err) {
|
||||
|
|
|
|||
|
|
@ -31,8 +31,7 @@
|
|||
"micromatch": "^4.0.2",
|
||||
"minify-xml": "^3.2.0",
|
||||
"svgo": "^4.0.0",
|
||||
"terser": "^5.3.0",
|
||||
"@mongodb-js/zstd": "^2.0.1"
|
||||
"terser": "^5.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"hexo": "^7.1.0",
|
||||
|
|
|
|||
|
|
@ -2,14 +2,16 @@
|
|||
'use strict'
|
||||
|
||||
const Hexo = require('hexo')
|
||||
const { compress: zstd, decompress: unzstd } = require('@mongodb-js/zstd')
|
||||
const zlib = require('zlib')
|
||||
const { promisify } = require('util')
|
||||
const zstd = promisify(zlib.zstdCompress)
|
||||
const unzstd = promisify(zlib.zstdDecompress)
|
||||
|
||||
describe('zstd', () => {
|
||||
const hexo = new Hexo(__dirname)
|
||||
const z = require('../lib/filter').zstdFn.bind(hexo)
|
||||
const path = 'foo.txt'
|
||||
const input = 'Lorem ipsum dolor sit amet consectetur adipiscing elit fusce'
|
||||
const inputBuf = Buffer.from(input, 'utf8')
|
||||
|
||||
beforeEach(() => {
|
||||
hexo.config.minify = {
|
||||
|
|
@ -36,7 +38,7 @@ describe('zstd', () => {
|
|||
output.on('data', (chunk) => (buf.push(chunk)))
|
||||
output.on('end', async () => {
|
||||
const result = Buffer.concat(buf)
|
||||
const expected = await zstd(inputBuf)
|
||||
const expected = await zstd(input)
|
||||
const resultUnzst = await unzstd(result)
|
||||
const expectedUnzst = await unzstd(expected)
|
||||
|
||||
|
|
@ -74,7 +76,7 @@ describe('zstd', () => {
|
|||
output.on('data', (chunk) => (buf.push(chunk)))
|
||||
output.on('end', async () => {
|
||||
const result = Buffer.concat(buf)
|
||||
const expected = await zstd(inputBuf, level)
|
||||
const expected = await zstd(input, { params: { [zlib.constants.ZSTD_c_compressionLevel]: level } })
|
||||
|
||||
expect(result.equals(expected)).toBe(true)
|
||||
})
|
||||
|
|
@ -98,7 +100,7 @@ describe('zstd', () => {
|
|||
output.on('data', (chunk) => (buf.push(chunk)))
|
||||
output.on('end', async () => {
|
||||
const result = Buffer.concat(buf)
|
||||
const expected = await zstd(inputBuf, undefined)
|
||||
const expected = await zstd(input, { params: { [zlib.constants.ZSTD_c_compressionLevel]: zlib.constants.ZSTD_CLEVEL_DEFAULT } })
|
||||
|
||||
expect(result.equals(expected)).toBe(true)
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue