I am stuggling with a function (normal given my lack of nim a C knowledge). The 
header contains: 
    
    
    extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file,
                             unz_file_info64 *pfile_info,
                             char *szFileName,
                             uLong fileNameBufferSize,
                             void *extraField,
                             uLong extraFieldBufferSize,
                             char *szComment,
                             uLong commentBufferSize));
    
    
    Run

and it is used like this: 
    
    
    err = 
unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
    
    
    Run

What I have done in nim so far: 
    
    
    #proc fmi_zip_unzip*(zip_file_path: cstring; output_folder: cstring;
    #                   callbacks: ptr jm_callbacks): jm_status_enu_t
    #int unzip(const char *zipfilename, const char *dirname);
    {.deadCodeElim: on.}
    #const libname = "/usr/lib/libminizip.so"
    
    #type
    #  unzFile* = pointer
    
    {.passl: gorge("pkg-config --libs minizip") .}
    {.passc: gorge("pkg-config --cflags minizip") .}
    
    #{.push header:"unzip.h"}
    
    #{.push dynlib:libname.}
    #unzFile ZEXPORT unzOpen64 OF((const void *path));
    #proc unzOpen64*(zipfilename: cstring): pointer 
#{.header:"<minizip-master/include/miniunz.h>".}
    #header:"unzip.h"
    type
      unz_global_info64* = ref object
        number_entry:uint64        # total number of entries in the central dir 
on this disk
        size_comment:uint32        # size of the global comment of the zipfile
      
      unz_global_info* = object
        number_entry:uint32        ## total number of entries in the central 
dir on this disk
        size_comment:uint32         ## size of the global comment of the zipfile
      
      tm_unz* = object
        tm_sec:uint16 #;            /* seconds after the minute - [0,59] */
        tm_min:uint16 #;            /* minutes after the hour - [0,59] */
        tm_hour:uint16 #;           /* hours since midnight - [0,23] */
        tm_mday:uint16 #;           /* day of the month - [1,31] */
        tm_mon:uint16  #;            /* months since January - [0,11] */
        tm_year:uint16  #;           /* years - [1980..2044] */
      
      unz_file_info64* = ref object
            version:uint16              # version made by                2 bytes
            version_needed:uint16       # version needed to extract      2 bytes
            flag:uint16                  # general purpose bit flag        2 
bytes
            compression_method:uint16   # compression method             2 bytes
            dosDate:uint32              # last mod file date in Dos fmt   4 
bytes
            crc:uint32                  # crc-32                         4 bytes
            compressed_size:uint64      # compressed size                8 bytes
            uncompressed_size:uint64    # uncompressed size              8 bytes
            size_filename:uint16         # filename length                 2 
bytes
            size_file_extra:uint16       # extra field length              2 
bytes
            size_file_comment:uint16     # file comment length             2 
bytes
            disk_num_start:uint16       # disk number start              2 bytes
            internal_fa:uint16          # internal file attributes        2 
bytes
            external_fa:uint32          # external file attributes        4 
bytes
            tmu_date:tm_unz
    
    
    
    {.push importc.}
    proc unzOpen64*(zipfilename: cstring): pointer #{. importc:"unzOpen64"}
    
    proc unzGetGlobalInfo64*(file:pointer, pglobal_info:unz_global_info64):int
    
    #type fname:char[256]
    proc unzGetCurrentFileInfo64*( file:pointer,
                                   pfile_info:unz_file_info64,
                                   szFileName:array[256,int],
                                   fileNameBufferSize:int,
                                   extraField:pointer,
                                   extraFieldBufferSize:uint64,
                                   szComment:cstring,
                                   commentBufferSize:uint64):int
    
    
    #{.pop.} # dynlib
    #{.pop.}
    {.pop.} # importc
    
    
    
    #var error:cint
    #var uf:unzFile
    var uf = unzOpen64("./test.zip")
    var info = new(unz_global_info64)
    var error = unzGetGlobalInfo64(uf,info)
    echo "----INFO----"
    echo repr(info)
    echo info.number_entry
    
    echo "----FILE LIST----"
    var filename_inzip:array[256,int] #cstring
    var pfile_info = new(unz_file_info64)
    var filename_len:int
    error = 
unzGetCurrentFileInfo64(uf,pfile_info,filename_inzip,filename_len,nil,0,""  ,0)
    echo "ERROR: ", error
    #echo "Version: ", pfile_info.version
    #echo pfile_info.size_filename
    #echo pfile_info.uncompressed_size
    echo "Name: ",$filename_inzip, filename_len
    echo repr(pfile_info)
    
    
    Run

What I get is: 
    
    
    ----INFO----
    ref 0x7f5ca1150048 --> [number_entry = 1,
    size_comment = 0]
    
    1
    ----FILE LIST----
    ERROR: 0
    Name: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]0
    ref 0x7f5ca1151048 --> [version = 798,
    version_needed = 0,
    flag = 0,
    compression_method = 0,
    dosDate = 20,
    crc = 0,
    compressed_size = 0,
    uncompressed_size = 8,
    size_filename = 36253,
    size_file_extra = 19852,
    size_file_comment = 0,
    disk_num_start = 0,
    internal_fa = 35672,
    external_fa = 0,
    tmu_date = [tm_sec = 1556,
    tm_min = 5,
    tm_hour = 0,
    tm_mday = 0,
    tm_mon = 1705,
    tm_year = 5]]
    
    
    Run

Obvously I was expecting the name of the file to have something. The values in 
general doesn't make much sense, so it looks I did something wrong. Does 
anybody can see it? 

Reply via email to