I'm using Julia's ZipFile package to extract and process csv files. No problem, but when I encounter a zip file within the zip file, I'd like to process that as well, but am encountering an error.
Julia ZipFile docs are here: https://zipfilejl.readthedocs.io/en/latest/
Here's the code:
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)
The call to ZipFile.Reader gives the error:
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>:?
So it seems ZipFile package cannot process a zip file from a zip file as it cannot do a seekend on it.
Any ideas on how to do this?
To unzip (extract) files or folders from a zipped folder To unzip a single file or folder, open the zipped folder, then drag the file or folder from the zipped folder to a new location.
Right-click on any of the zip files that are a part of the collection and click on the "Extract here" or "Extract to folder" option in the pop-up menu. Your zip application will load up and begin decompressing all the files.
Open File Explorer and find the zipped folder. To unzip the entire folder, right-click to select Extract All, and then follow the instructions. To unzip a single file or folder, double-click the zipped folder to open it. Then, drag or copy the item from the zipped folder to a new location.
A workaround is to read the zip file into an IOBuffer. ZipFile.Reader is able to process the IOBuffer. Here is the working code:
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With