Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define nb_available for ZipFile.ReadableFile #39

Open
felipenoris opened this issue Apr 29, 2018 · 3 comments
Open

Define nb_available for ZipFile.ReadableFile #39

felipenoris opened this issue Apr 29, 2018 · 3 comments

Comments

@felipenoris
Copy link

I'm hitting this error when reading a XML file with EzXML.jl , when the XML is inside a zip file.

ERROR: MethodError: no method matching nb_available(::ZipFile.ReadableFile)

Is it possible to define this function?

@felipenoris
Copy link
Author

felipenoris commented Apr 29, 2018

This is the testing script:

julia> using EzXML, ZipFile

julia> filepath="general.xlsx"; xlfile = ZipFile.Reader(filepath); f1=xlfile.files[1]
ZipFile.ReadableFile(name=[Content_Types].xml, method=Deflate, uncompresssedsize=2521, compressedsize=396, mtime=3.155436e8)

julia> doc = EzXML.readxml(f1)
ERROR: MethodError: no method matching nb_available(::ZipFile.ReadableFile)
Closest candidates are:
  nb_available(::Base.Filesystem.File) at filesystem.jl:162
  nb_available(::BufferStream) at stream.jl:1155
  nb_available(::IOStream) at iostream.jl:185
  ...
Stacktrace:
 [1] (::EzXML.##7#8)(::Ptr{Void}, ::Ptr{UInt8}, ::Int32) at /home/felipenoris/.julia/v0.6/EzXML/src/document.jl:203
 [2] macro expansion at /home/felipenoris/.julia/v0.6/EzXML/src/error.jl:50 [inlined]
 [3] readxml(::ZipFile.ReadableFile) at /home/felipenoris/.julia/v0.6/EzXML/src/document.jl:141

The file general.xlsx can be any Excel file.

cc @bicycle1885

@fhs
Copy link
Owner

fhs commented Apr 30, 2018

I think nb_available can be just be f.uncompressedsize - f._pos. See the read function:

if eof(f) || f._pos+length(a)*sizeof(T) > f.uncompressedsize

That's assuming the uncompressed size is accurate in the metadata. Maybe it's better to call Zlib's nb_available (if it's even available)? I'd need to look into it in more detail.

@felipenoris
Copy link
Author

@fhs , thanks! That actually worked!

Base.nb_available(f::ZipFile.ReadableFile) = f.uncompressedsize - f._pos

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants