diff options
| author | ruki <[email protected]> | 2024-08-22 00:42:29 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-08-22 00:42:29 +0800 |
| commit | 7b05f6e814dedea34ca11a27833e7c39c3afe246 (patch) | |
| tree | 79f1c422d3fba0e1e022cde138d49a2bf4b8a527 | |
| parent | 8c55e952b6ff2c520f4fab685f9b234a5ed194e1 (diff) | |
impl extract files
| -rw-r--r-- | xmake/modules/utils/archive/archive_xmz.lua | 4 | ||||
| -rw-r--r-- | xmake/modules/utils/archive/extract_xmz.lua | 36 | ||||
| -rw-r--r-- | xmake/repository/xmake.lua | 3 |
3 files changed, 39 insertions, 4 deletions
diff --git a/xmake/modules/utils/archive/archive_xmz.lua b/xmake/modules/utils/archive/archive_xmz.lua index 96c83490b..6cf2c13aa 100644 --- a/xmake/modules/utils/archive/archive_xmz.lua +++ b/xmake/modules/utils/archive/archive_xmz.lua @@ -20,14 +20,18 @@ -- imports import("core.base.option") +import("core.base.bytes") import("core.compress.lz4") -- archive files function _archive_files(archivefile, inputfiles, opt) local outputfile = io.open(archivefile, "wb") for _, inputfile in ipairs(inputfiles) do + outputfile:write(bytes(2):u16be_set(1, #inputfile)) outputfile:write(inputfile) local data = io.readfile(inputfile, {encoding = "binary"}) + vprint("archiving %s, %d bytes", inputfile, data and #data or 0) + outputfile:write(bytes(4):u32be_set(1, #data)) outputfile:write(data) end outputfile:close() diff --git a/xmake/modules/utils/archive/extract_xmz.lua b/xmake/modules/utils/archive/extract_xmz.lua index 1b6cdec04..1b09c0679 100644 --- a/xmake/modules/utils/archive/extract_xmz.lua +++ b/xmake/modules/utils/archive/extract_xmz.lua @@ -20,8 +20,41 @@ -- imports import("core.base.option") +import("core.base.bytes") import("core.compress.lz4") +-- extract files +function _extract_files(archivefile, outputdir, opt) + local inputfile = io.open(archivefile, "rb") + local filesize = inputfile:size() + local readsize = 0 + while readsize < filesize do + local data = inputfile:read(2) + local size = bytes(data):u16be(1) + local filepath + if size > 0 then + filepath = inputfile:read(size) + end + readsize = readsize + 2 + size + data = inputfile:read(4) + size = bytes(data):u32be(1) + local filedata + if size > 0 then + filedata = inputfile:read(size) + end + readsize = readsize + 4 + size + if filepath then + vprint("extracting %s, %d bytes", filepath, filedata and #filedata or 0) + if filedata then + io.writefile(path.join(outputdir, filepath), filedata, {encoding = "binary"}) + else + os.touch(filepath) + end + end + end + inputfile:close() +end + -- decompress file function _decompress_file(archivefile, outputfile, opt) lz4.decompress_file(archivefile, outputfile) @@ -37,6 +70,7 @@ function main(archivefile, outputdir, opt) opt = opt or {} local archivefile_tmp = os.tmpfile({ramdisk = false}) - _decompress_file(archivefile, archivefile_tmp) + _decompress_file(archivefile, archivefile_tmp, opt) + _extract_files(archivefile_tmp, outputdir, opt) os.tryrm(archivefile_tmp) end diff --git a/xmake/repository/xmake.lua b/xmake/repository/xmake.lua deleted file mode 100644 index 01c381ed3..000000000 --- a/xmake/repository/xmake.lua +++ /dev/null @@ -1,3 +0,0 @@ - --- set repository description -set_description("The official builtin package repository of xmake") |
