libs-imp-lzma.lmt /size: 1626 b    last modification: 2021-10-28 13:51
1if not modules then modules = { } end modules ['libs-imp-lzma'] = {
2    version   = 1.001,
3    comment   = "companion to luat-lib.mkxl",
4    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5    copyright = "PRAGMA ADE / ConTeXt Development Team",
6    license   = "see context related readme files"
7}
8
9-- Instead of linking in libs like this we now do them optional. After all, once
10-- we start adding more and more stuff statically we en dup with a mess.
11
12-- e:\tex-context\tex\texmf-win64\bin\lib\luametatex\lzma\liblzma.dll
13
14local libname = "lzma"
15local libfile = "liblzma"
16
17local lzmalib = resolvers.libraries.validoptional(libname)
18
19if not lzmalib then return end
20
21local lzma_compress   = lzmalib.compress
22local lzma_decompress = lzmalib.decompress
23
24local function okay()
25    if resolvers.libraries.optionalloaded(libname,libfile) then
26        okay = function() return true end
27    else
28        okay = function() return false end
29    end
30    return okay()
31end
32
33local lzma = {
34    compress   = function (...) return okay() and lzma_compress       (...) end,
35    decompress = function (...) return okay() and lzma_decompress     (...) end,
36}
37
38package.loaded[libname] = lzma
39
40-- local raw = io.loaddata("e:/luatex/luametatex-source.tar")
41-- local old = io.loaddata("e:/luatex/luametatex-source.tar.xz")
42-- local new = lzma.decompress(old)
43-- local xz1 = lzma.compress(raw,9)
44-- local xz2 = lzma.decompress(xz1)
45
46-- print("raw",raw and #raw)
47-- print("old",old and #old)
48-- print("new",new and #new)
49-- print("chk",new == raw)
50-- print("xz1",xz1 and #xz1)
51-- print("xz2",xz2 and #xz2)
52-- print("chk",xz2 == raw)
53
54return lzma
55