Skip to content

Define nb_available for ZipFile.ReadableFile #39

Open

Description

@felipenoris

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?

Activity

  1. felipenoris commented on Apr 29, 2018

    @felipenoris
    Author

    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

  2. fhs commented on Apr 30, 2018

    @fhs
    Owner

    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.

  3. felipenoris commented on Apr 30, 2018

    @felipenoris
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions