如何使用Lua从zip文件中提取文件?

如何使用Lua提取文件?

更新:我现在有以下代码,但每次到达函数末尾时都会崩溃,但它成功提取所有文件并将它们放在正确的位置.

require "zip"

function ExtractZipAndCopyFiles(zipPath,zipFilename,destinationPath)
    local zfile,err = zip.open(zipPath .. zipFilename)

    -- iterate through each file insize the zip file
    for file in zfile:files() do
        local currFile,err = zfile:open(file.filename)
        local currFileContents = currFile:read("*a") -- read entire contents of current file
        local hBinaryOutput = io.open(destinationPath .. file.filename,"wb")

        -- write current file inside zip to a file outside zip
        if(hBinaryOutput)then
            hBinaryOutput:write(currFileContents)
            hBinaryOutput:close()
        end
    end

    zfile:close()
end
-- call the function
ExtractZipAndCopyFiles("C:\\Users\\bhannan\\Desktop\\LUA\\","example.zip","C:\\Users\\bhannan\\Desktop\\ZipExtractionOutput\\")

为什么每次到达时都会崩溃?

解决方法

简答:

LuaZip是一个轻量级的Lua扩展库,用于读取存储在zip文件中的文件. API与标准的Lua I / O库API非常相似.

使用LuaZip从存档中读取文件,然后使用Lua io module将它们写入文件系统.如果需要ANSI C不支持的文件系统操作,请查看LuaFileSystem. LuaFileSystem是一个Lua库,用于补充相关的函数集归档标准Lua发行版提供的系统. LuaFileSystem提供了一种可移植的方式来访问底层目录结构和文件属性.

进一步阅读:

LAR是Lua使用ZIP压缩的虚拟文件系统.

如果您需要阅读gzip流或gzip压缩tar files,请查看gzio. Lua gzip文件I / O模块模拟标准I / O模块,但在压缩的gzip格式文件上运行.

相关文章

1.github代码实践源代码是lua脚本语言,下载th之后运行thmai...
此文为搬运帖,原帖地址https://www.cnblogs.com/zwywilliam/...
Rime输入法通过定义lua文件,可以实现获取当前时间日期的功能...
localfunctiongenerate_action(params)localscale_action=cc...
2022年1月11日13:57:45 官方:https://opm.openresty.org/官...
在Lua中的table(表),就像c#中的HashMap(哈希表),key和...