加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-15 00:26:20 所属栏目:大数据 来源:网络整理
导读:如何使用Lua提取文件? 更新:我现在有以下代码,但每次到达函数末尾时都会崩溃,但它成功提取所有文件并将它们放在正确的位置. require "zip"function ExtractZipAndCopyFiles(zipPath,zipFilename,destinationPath) local zfile,err = zip.open(zipPath .. z
如何使用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:UsersbhannanDesktopLUA","example.zip","C:UsersbhannanDesktopZipExtractionOutput")

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

解决方法

简答:

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格式文件上运行.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读