data-dec.lua /size: 1557 b    last modification: 2021-10-28 13:50
1
if
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 9
local
loaddata
=
io
.
loaddata
10
local
suffix
=
file
.
suffix
11
local
resultof
=
os
.
resultof
12 13
local
decompressors
=
{
}
14
resolvers
.
decompressors
=
decompressors
15 16
local
decompresslzma
=
nil
17
local
decompressgzip
=
gzip
.
decompress
18 19
local
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
-- todo: use a proper runner
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
40
end
41 42
local
cache
=
table
.
setmetatableindex
(
function
(
t
,
k
)
43
local
v
=
decompressed
(
k
)
or
false
44
t
[
k
]
=
v
45
return
v
46
end
)
47 48
decompressors
.
decompress
=
decompress
49 50
function
decompressors
.
register
(
filename
)
51
return
cache
[
filename
]
52
end
53 54
function
decompressors
.
unregister
(
filename
)
55
cache
[
filename
]
=
nil
56
end
57