1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
if not modules then modules = { } end modules ['libs-imp-zstd'] = {
version = 1.001,
comment = "companion to luat-lib.mkxl",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
copyright = "PRAGMA ADE / ConTeXt Development Team",
license = "see context related readme files"
}
-- Instead of linking in libs like this we now do them optional. After all, once
-- we start adding more and more stuff statically we en dup with a mess. In fact,
-- this lib was the reason for no longer embedding lzo and lz4.
-- c:/data/develop/tex-context/tex/texmf-win64/bin/lib/luametatex/lua/copies/curl/libzstd.dll
-- require("libs-imp-zstd.lmt") -- only loads
--
-- local zstd = require("zstd") -- activates
--
-- local data = io.loaddata("t:/sources/char-def.lua")
-- local comp = zstd.compress (data)
-- local back = zstd.decompress(comp)
--
-- print(#data,#comp,#back,#back==#data)
local libname = "zstd"
local libfile = "libzstd"
local zstdlib = resolvers.libraries.validoptional(libname)
if not zstdlib then return end
local zstd_compress = zstdlib.compress
local zstd_decompress = zstdlib.decompress
local function okay()
if resolvers.libraries.optionalloaded(libname,libfile) then
okay = function() return true end
else
okay = function() return false end
end
return okay()
end
local zstd = {
compress = function (s) return okay() and zstd_compress (s) end,
decompress = function (s) return okay() and zstd_decompress(s) end,
}
package.loaded[libname] = zstd
return zstd
-- local foreign = optional.loaded.foreign
-- local newbuffer = foreign.newbuffer
-- local getbuffer = foreign.getbuffer
--
-- local zstd = foreign.load("libzstd")
--
-- local ZSTD_compressBound = zstd:register {
-- name = "ZSTD_compressBound",
-- result = "int",
-- arguments = { "int" },
-- }
--
-- local ZSTD_getFrameContentSize = zstd:register {
-- name = "ZSTD_getFrameContentSize",
-- result = "int",
-- arguments = { "pointer", "int" },
-- }
--
-- local ZSTD_compress = zstd:register {
-- name = "ZSTD_compress",
-- result = "int",
-- arguments = { "pointer", "int", "string", "int", "int" },
-- arguments = { "pointer", "int", "pointer", "int", "int" },
-- }
--
-- local ZSTD_decompress = zstd:register {
-- name = "ZSTD_decompress",
-- result = "int",
-- arguments = { "pointer", "int", "string", "int" },
-- }
--
-- local function zstd_compress(source,level)
-- local sourcesize = #source
-- local targetsize = ZSTD_compressBound(sourcesize)
-- local target = newbuffer(targetsize)
-- local result = ZSTD_compress(target,targetsize,source,sourcesize,tonumber(level) or 3)
-- return getbuffer(target,result)
-- end
--
-- local function zstd_decompress(source)
-- local sourcesize = #source
-- local targetsize = ZSTD_getFrameContentSize(source,sourcesize)
-- local target = newbuffer(targetsize)
-- local result = ZSTD_decompress(target,targetsize,source,sourcesize)
-- return getbuffer(target,result)
-- end
|