首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Julia:在Zip文件中提取Zip文件

Julia:在Zip文件中提取Zip文件
EN

Stack Overflow用户
提问于 2017-07-03 10:08:54
回答 1查看 1.7K关注 0票数 6

我正在使用Julia的ZipFile包来提取和处理csv文件。没问题,但是当我在zip文件中遇到zip文件时,我也想处理它,但是遇到了一个错误。

Julia ZipFile文档在这里:https://zipfilejl.readthedocs.io/en/latest/

代码如下:

代码语言:javascript
运行
复制
using ZipFile
using DataFrames
function process_zip(zip::ZipFile.ReadableFile)

    if split(zip.name,".")[end] == "zip"

        r = ZipFile.Reader(zip) #error: MethodError: no method matching seekend(::ZipFile.ReadableFile)

        for f in r.files
            process_zip(f) 
        end
    end

    if split(zip.name,".")[end] == "csv"
         df = readtable(zip) #for now just read it into a dataframe
    end

end

r = ZipFile.Reader("yourzipfilepathhere");

for f in r.files
    process_zip(f)
end
close(r)

对ZipFile.Reader的调用给出了错误:

代码语言:javascript
运行
复制
MethodError: no method matching seekend(::ZipFile.ReadableFile)
Closest candidates are:
  seekend(::Base.Filesystem.File) at filesystem.jl:191
  seekend(::IOStream) at iostream.jl:57
  seekend(::Base.AbstractIOBuffer) at iobuffer.jl:178
  ...

Stacktrace:
 [1] _find_enddiroffset(::ZipFile.ReadableFile) at /home/chuck/.julia/v0.6/ZipFile/src/ZipFile.jl:259
 [2] ZipFile.Reader(::ZipFile.ReadableFile, ::Bool) at /home/chuck/.julia/v0.6/ZipFile/src/ZipFile.jl:104
 [3] process_zip(::ZipFile.ReadableFile) at ./In[27]:7
 [4] macro expansion at ./In[27]:18 [inlined]
 [5] anonymous at ./<missing>:?

所以看起来ZipFile包不能处理来自压缩文件的压缩文件,因为它不能对它做搜索结束。

你有什么建议吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-07-03 11:26:29

解决方法是将压缩文件读取到IOBuffer中。ZipFile.Reader能够处理IOBuffer。以下是工作代码:

代码语言:javascript
运行
复制
using ZipFile
using DataFrames
function process_zip(zip::ZipFile.ReadableFile)

    if split(zip.name,".")[end] == "zip"

        iobuffer = IOBuffer(readstring(zip))
        r = ZipFile.Reader(iobuffer)

        for f in r.files
            process_zip(f) 
        end
    end

    if split(zip.name,".")[end] == "csv"
         df = readtable(zip) #for now just read it into a dataframe
    end

end

r = ZipFile.Reader("yourzipfilepathhere");

for f in r.files
    process_zip(f)
end
close(r)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44876852

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档