/luabrotli

Lua binding for Brotli compression library

Primary LanguageC++GNU General Public License v2.0GPL-2.0

luabrotli

Lua binding for Brotli compression library

Dependencies

Usage

Compression

local brotli = require 'luabrotli'

local input = [[
Lorem ipsum dolor sit amet...
]]

local outputBufferSize = 4096

-- Omitted parameters are set to defaults.
local parameters = {
	--[[
		brotli.mode.GENERIC 		-	Default compression mode.
		brotli.mode.TEXT			-	Compression mode for UTF-8 format text input.
		brotli.mode.FONT			-	Compression mode used in WOFF 2.0.
	--]]
	mode = brotli.mode.GENERIC,

	-- Compression quality: 0 (Worst) - 11 (Best)
	quality = 11,

	-- Base 2 logarithm of the sliding window size. Range is 10 to 24.
	lgwin = 11,

	-- Base 2 logarithm of the maximum input block size. Range is 16 to 24.
	lgblock = 11,

	enable_dictionary = true,
	enable_transforms = false,
	greedy_block_split = false,
	enable_context_modeling = true,
}
local out = assert(brotli.compress(parameters, input, outputBufferSize))

Decompression

local brotli = require 'luabrotli'

local input = [[
Lorem ipsum dolor sit amet...
]]

local outputBufferSize = 4096
local out = assert(brotli.compress({}, input, outputBufferSize))

local original = assert(brotli.decompress(out, brotli.decompressedSize(out)))