diff options
author | Hans Hagen <pragma@wxs.nl> | 2021-06-24 19:37:45 +0200 |
---|---|---|
committer | Context Git Mirror Bot <phg@phi-gamma.net> | 2021-06-24 19:37:45 +0200 |
commit | 820657bb1e9acfb36f24dfa8801526b0d5f2b464 (patch) | |
tree | fc93fd3936e84b9b0a6402719e185d35e332eee9 /tex/context/base/mkiv/l-gzip.lua | |
parent | 4272a26c49cbfee8917e5272fc0f964cbcfc4b03 (diff) | |
download | context-820657bb1e9acfb36f24dfa8801526b0d5f2b464.tar.gz |
2021-06-24 18:52:00
Diffstat (limited to 'tex/context/base/mkiv/l-gzip.lua')
-rw-r--r-- | tex/context/base/mkiv/l-gzip.lua | 174 |
1 files changed, 1 insertions, 173 deletions
diff --git a/tex/context/base/mkiv/l-gzip.lua b/tex/context/base/mkiv/l-gzip.lua index f141b5ebb..aadb781da 100644 --- a/tex/context/base/mkiv/l-gzip.lua +++ b/tex/context/base/mkiv/l-gzip.lua @@ -5,176 +5,4 @@ if not modules then modules = { } end modules ['l-gzip'] = { license = "see context related readme files" } --- We only have a few official methods here: --- --- local decompressed = gzip.load (filename) --- local resultsize = gzip.save (filename,compresslevel) --- local compressed = gzip.compress (str,compresslevel) --- local decompressed = gzip.decompress (str) --- local iscompressed = gzip.compressed (str) --- local suffix, okay = gzip.suffix (filename) --- --- In LuaMetaTeX we have only xzip which implements a very few methods: --- --- compress (str,level,method,window,memory,strategy) --- decompress (str,window) --- adler32 (str,checksum) --- crc32 (str,checksum) --- --- Special window values are: --- --- flate : - 15 --- zlib : 15 --- gzip : 15 | 16 --- auto : 15 | 32 - -gzip = gzip or { } -- so in luatex we keep the old ones too - -if not zlib then - zlib = xzip -- in luametatex we shadow the old one -elseif not xzip then - xzip = zlib -end - -if zlib then - - local suffix = file.suffix - local suffixes = file.suffixes - local find = string.find - local openfile = io.open - - local gzipwindow = 15 + 16 -- +16: gzip, +32: gzip|zlib - local gziplevel = 3 - local identifier = "^\x1F\x8B\x08" - - local compress = zlib.compress - local decompress = zlib.decompress - - function gzip.load(filename) - local f = openfile(filename,"rb") - if not f then - -- invalid file - else - local data = f:read("*all") - f:close() - if data and data ~= "" then - if suffix(filename) == "gz" then - data = decompress(data,gzipwindow) - end - return data - end - end - end - - function gzip.save(filename,data,level) - if suffix(filename) ~= "gz" then - filename = filename .. ".gz" - end - local f = openfile(filename,"wb") - if f then - data = compress(data or "",level or gziplevel,nil,gzipwindow) - f:write(data) - f:close() - return #data - end - end - - function gzip.suffix(filename) - local suffix, extra = suffixes(filename) - local gzipped = extra == "gz" - return suffix, gzipped - end - - function gzip.compressed(s) - return s and find(s,identifier) - end - - function gzip.compress(s,level) - if s and not find(s,identifier) then -- the find check might go away - if not level then - level = gziplevel - elseif level <= 0 then - return s - elseif level > 9 then - level = 9 - end - return compress(s,level or gziplevel,nil,gzipwindow) or s - end - end - - function gzip.decompress(s) - if s and find(s,identifier) then - return decompress(s,gzipwindow) - else - return s - end - end - -end - --- In luametatex we can use this one but it doesn't look like there wil be stream --- support so for now we still use zlib (the performance difference is not that --- spectacular in our usage. - --- if flate then --- --- local type = type --- local find = string.find --- --- local compress = flate.gz_compress --- local decompress = flate.gz_decompress --- --- local absmax = 128*1024*1024 --- local initial = 64*1024 --- local identifier = "^\x1F\x8B\x08" --- --- function gzip.compressed(s) --- return s and find(s,identifier) --- end --- --- function gzip.compress(s,level) --- if s and not find(s,identifier) then -- the find check might go away --- if not level then --- level = 3 --- elseif level <= 0 then --- return s --- elseif level > 9 then --- level = 9 --- end --- return compress(s,level) or s --- end --- end --- --- function gzip.decompress(s,size,iterate) --- if s and find(s,identifier) then --- if type(size) ~= "number" then --- size = initial --- end --- if size > absmax then --- size = absmax --- end --- if type(iterate) == "number" then --- max = size * iterate --- elseif iterate == nil or iterate == true then --- iterate = true --- max = absmax --- end --- if max > absmax then --- max = absmax --- end --- while true do --- local d = decompress(s,size) --- if d then --- return d --- end --- size = 2 * size --- if not iterate or size > max then --- return false --- end --- end --- else --- return s --- end --- end --- --- end +-- now in util-zip |