ws-arch: archive/7z reads BZip2 (codecs/Bzip2) and Zstd (codecs/Zstd) coders; fixtures test BZip2 solid + BCJ

This commit is contained in:
4DBug committed 2026-10-31 08:55:24 -05:00
1 parent a9110bdab2
commit 6226ec41e4
4 files changed
+26 -8

No files matched your search

+1 -1
View File
@@ -80,7 +80,7 @@ local list: { Entry } = {
path = "archive/7z",
extensions = { "7z" },
mime = { "application/x-7z-compressed" },
deps = { "core/Err", "core/Bytes", "core/Crc32", "Types", "codecs/Lzma", "codecs/Deflate", "containers/Archive" },
deps = { "core/Err", "core/Bytes", "core/Crc32", "Types", "codecs/Lzma", "codecs/Deflate", "codecs/Bzip2", "codecs/Zstd", "containers/Archive" },
caps = { decode = true, encode = false, methods = { "copy", "lzma", "lzma2", "deflate", "bcj", "delta" }, encrypted = false },
load = function()
return require("@formats/archive/7z")
+21 -4
View File
@@ -1,11 +1,12 @@
--!strict
-- archive/7z: 7z archives (7zFormat.txt from the LZMA SDK, Igor Pavlov, public domain), read as an Archive whose
-- entries decode lazily (a folder is decoded once on first read, then sliced). Supports: plain and encoded (compressed)
-- headers, solid and non-solid folders, coder chains of copy / LZMA / LZMA2 / Deflate with BCJ (x86, PowerPC, ARM,
-- headers, solid and non-solid folders, coder chains of copy / LZMA / LZMA2 / Deflate / BZip2 /
-- Zstd (7-Zip-zstd's plain frames; untested: stock 7-Zip cannot write it) with BCJ (x86, PowerPC, ARM,
-- ARM-Thumb, SPARC, ARM64) and delta filters, empty files and directories, anti items (skipped), UTF-16 names, mtimes,
-- Windows / Unix attributes, folder and file CRC-32s (verified on read).
-- Not supported (Err.UNSUPPORTED naming the method, on read of the affected entries): BZip2, PPMd, BCJ2, Deflate64,
-- Zstd and other plug-in codecs, AES encryption, multi-volume archives, external header references; writing.
-- Not supported (Err.UNSUPPORTED naming the method, on read of the affected entries): PPMd, BCJ2, Deflate64, other
-- plug-in codecs (Brotli, LZ4, ...), AES encryption, multi-volume archives, external header references; writing.
-- ------------------------------------------------------------------------------------------------ requires
local Err = require("@formats/core/Err")
@@ -14,6 +15,8 @@ local Crc32 = require("@formats/core/Crc32")
local Types = require("@formats/Types")
local Lzma = require("@formats/codecs/Lzma")
local Deflate = require("@formats/codecs/Deflate")
local Bzip2 = require("@formats/codecs/Bzip2")
local Zstd = require("@formats/codecs/Zstd")
local Archive = require("@formats/containers/Archive")
local Header = require("@formats/archive/7z/Header")
@@ -23,7 +26,7 @@ local SevenZip = {
category = "archive",
extensions = { "7z" },
mime = { "application/x-7z-compressed" },
deps = { "core/Err", "core/Bytes", "core/Crc32", "Types", "codecs/Lzma", "codecs/Deflate", "containers/Archive" },
deps = { "core/Err", "core/Bytes", "core/Crc32", "Types", "codecs/Lzma", "codecs/Deflate", "codecs/Bzip2", "codecs/Zstd", "containers/Archive" },
caps = { decode = true, encode = false, methods = { "copy", "lzma", "lzma2", "deflate", "bcj", "delta" }, encrypted = false },
}
@@ -179,6 +182,20 @@ local function decodeFolder(ctx: Ctx, s: Header.Streams, f: Header.Folder): (buf
elseif id == "\4\1\8" then
local b, e = Deflate.inflate(src, so, sl, size)
return b, if b then nil else e
elseif id == "\4\2\2" or id == "\4\247\17\1" then -- BZip2, Zstd (7-Zip-zstd: plain zstd frames)
local b, e
if id == "\4\2\2" then
b, e = Bzip2.decompress(src, so, sl, opts)
else
b, e = Zstd.decompress(src, so, sl, opts)
end
if not b then
return nil, e
end
if buffer.len(b) ~= size then
return nil, Err.new(Err.CORRUPT, methodName(id) .. " stream decodes to the wrong size")
end
return b
elseif FILTERS[id] then
if sl ~= size then
return nil, Err.new(Err.CORRUPT, "filter size mismatch")