Repository URL to install this package:
Version:
1.0.2-1.el8 ▾
|
local _M = { _VERSION = '1.0' }
local brotlienc = require "resty.brotli.encoder"
local brotlidec = require "resty.brotli.decoder"
local mt = { __index = _M }
function _M.new()
return setmetatable({
encoder = brotlienc:new(),
decoder = brotlidec:new(),
}, mt)
end
-- Return encoded, err
--[[
config : {
quality = 0 to 11 (Default 11),
lgwin = Set Brotli window size. Window size is (1 << lgwin) - 16.,
mode = <BROTLI_MODE_GENERIC (0) | BROTLI_MODE_TEXT (1, for UTF-8 format text input) | BROTLI_MODE_FONT (2, for WOFF 2.0) >
}
--]]
function _M.encode(self, input, config)
if input == nil or type(input) ~= "string" then
return nil, "Invalid input pass ".. type(input)
end
local encoder = self.encoder
if not encoder then
return nil, "Encoder is nil"
end
return encoder:compressStream(input, config)
end
-- Return encoded, err
function _M.decode(self, input)
if input == nil or type(input) ~= "string" then
return
end
local decoder = self.decoder
if not decoder then
return nil
end
return decoder:decompressStream(input)
end
function _M.destroy(self)
self.encoder:destroy()
self.decoder:destroy()
end
return _M