1if not modules then modules = { } end modules ['data-dec'] = {
2 version = 1.001,
3 comment = "companion to luat-lib.mkiv",
4 author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5 copyright = "PRAGMA ADE / ConTeXt Development Team",
6 license = "see context related readme files"
7}
8
9local loaddata = io.loaddata
10local suffix = file.suffix
11local resultof = os.resultof
12
13local decompressors = { }
14resolvers.decompressors = decompressors
15
16local decompresslzma = nil
17local decompressgzip = gzip.decompress
18
19local function decompressed(k)
20 local s = suffix(k)
21 if s == "xz" then
22 if decompresslzma == nil then
23 local lzma = require(resolvers.findfile("libs-imp-lzma.lmt"))
24 if lzma then
25 local decompress = lzma.decompress
26 decompresslzma = function(name)
27 return decompress(loaddata(k))
28 end
29 else
30 decompresslzma = function(name)
31
32 return resultof("xz -d -c -q -q " .. name)
33 end
34 end
35 end
36 return decompresslzma(k)
37 elseif s == "gz" then
38 return decompressgzip(loaddata(k))
39 end
40end
41
42local cache = table.setmetatableindex(function(t,k)
43 local v = decompressed(k) or false
44 t[k] = v
45 return v
46end)
47
48decompressors.decompress = decompress
49
50function decompressors.register(filename)
51 return cache[filename]
52end
53
54function decompressors.unregister(filename)
55 cache[filename] = nil
56end
57 |