[latex3-commits] [git/LaTeX3-latex3-lualibs] new-libs: Import from ConTeXt (0ab8139)
Marcel Fabian Krüger
tex at 2krueger.de
Sat Mar 12 14:12:10 CET 2022
Repository : https://github.com/latex3/lualibs
On branch : new-libs
Link : https://github.com/latex3/lualibs/commit/0ab8139b0dde2a9317b71893cfca120cbcedc222
>---------------------------------------------------------------
commit 0ab8139b0dde2a9317b71893cfca120cbcedc222
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date: Sat Mar 12 14:12:10 2022 +0100
Import from ConTeXt
>---------------------------------------------------------------
0ab8139b0dde2a9317b71893cfca120cbcedc222
lualibs-util-sac.lua | 36 ++++++++++++++++++++++++++++++++++++
lualibs-util-zip.lua | 30 +++++++++++++++++++-----------
2 files changed, 55 insertions(+), 11 deletions(-)
diff --git a/lualibs-util-sac.lua b/lualibs-util-sac.lua
index 796a620..36daef8 100644
--- a/lualibs-util-sac.lua
+++ b/lualibs-util-sac.lua
@@ -544,3 +544,39 @@ do
end
end
+
+if bit32 and not streams.tocardinal1 then
+
+ local extract = bit32.extract
+ local char = string.char
+
+ streams.tocardinal1 = char
+ function streams.tocardinal2(n) return char(extract( 8,8),extract( 0,8)) end
+ function streams.tocardinal3(n) return char(extract(16,8),extract( 8,8),extract(0,8)) end
+ function streams.tocardinal4(n) return char(extract(24,8),extract(16,8),extract(8,8),extract(0,8)) end
+
+ streams.tocardinal1le = char
+ function streams.tocardinal2le(n) return char(extract(0,8),extract(8,8)) end
+ function streams.tocardinal3le(n) return char(extract(0,8),extract(8,8),extract(16,8)) end
+ function streams.tocardinal4le(n) return char(extract(0,8),extract(8,8),extract(16,8),extract(24,8)) end
+
+end
+
+if not streams.readcstring then
+
+ local readchar = streams.readchar
+ local concat = table.concat
+
+ function streams.readcstring(f)
+ local t = { }
+ while true do
+ local c = readchar(f)
+ if c and c ~= "\0" then
+ t[#t+1] = c
+ else
+ return concat(t)
+ end
+ end
+ end
+
+end
diff --git a/lualibs-util-zip.lua b/lualibs-util-zip.lua
index d478eae..bd8fdf2 100644
--- a/lualibs-util-zip.lua
+++ b/lualibs-util-zip.lua
@@ -48,6 +48,11 @@ local zlibdecompress = zlib.decompress
local zlibdecompresssize = zlib.decompresssize
local zlibchecksum = zlib.crc32
+if not CONTEXTLMTXMODE or CONTEXTLMTXMODE == 0 then
+ local cs = zlibchecksum
+ zlibchecksum = function(str,n) return cs(n or 0, str) end
+end
+
local decompress = function(source) return zlibdecompress (source,-15) end -- auto
local decompresssize = function(source,targetsize) return zlibdecompresssize(source,targetsize,-15) end -- auto
local calculatecrc = function(buffer,initial) return zlibchecksum (initial or 0,buffer) end
@@ -565,7 +570,12 @@ else
local compress = zlib.compress
local decompress = zlib.decompress
- local crc32 = zlib.crc32
+ local zlibchecksum = zlib.crc32
+
+ if not CONTEXTLMTXMODE or CONTEXTLMTXMODE == 0 then
+ local cs = zlibchecksum
+ zlibchecksum = function(str,n) return cs(n or 0, str) end
+ end
local streams = utilities.streams
local openstream = streams.openstring
@@ -606,16 +616,16 @@ else
putcompressed = function(str,level,originalname)
return concat {
- identifier, -- 2 identifier
- tocardinal1(0x08), -- 1 method
- tocardinal1(0x08), -- 1 flags
- tocardinal4(os.time()), -- 4 mtime
- tocardinal1(0x02), -- 1 compression (2 or 4)
- tocardinal1(0xFF), -- 1 operating
+ identifier, -- 2 identifier
+ tocardinal1(0x08), -- 1 method
+ tocardinal1(0x08), -- 1 flags
+ tocardinal4(os.time()), -- 4 mtime
+ tocardinal1(0x02), -- 1 compression (2 or 4)
+ tocardinal1(0xFF), -- 1 operating
(originalname or "unknownname") .. "\0",
compress(str,level,nil,gzipwindow),
- tocardinal4(crc32(str)), -- 4
- tocardinal4(#str), -- 4
+ tocardinal4(zlibchecksum(str)), -- 4
+ tocardinal4(#str), -- 4
}
end
@@ -671,6 +681,4 @@ function gzip.decompress(s)
end
end
-zipfiles.gunzipfile = gzip.load
-
-- return zipfiles
More information about the latex3-commits
mailing list.