ZIP / UnZIP

New to FreeBASIC? Post your questions here.
MrSwiss
Posts: 3307
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: ZIP / UnZIP

Postby MrSwiss » May 27, 2017 12:40

Where do I get the 64bit version of *libzip* from?

WIN32, is on the way out (as WIN16 before).
WIN64, is the future ... (I got the 64bit *libz* already)
St_W
Posts: 1479
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: ZIP / UnZIP

Postby St_W » May 28, 2017 22:10

MrSwiss wrote:Where do I get the 64bit version of *libzip* from?

WIN32, is on the way out (as WIN16 before).
WIN64, is the future ... (I got the 64bit *libz* already)

fxm wrote:You can get 'libz.a' at:
http://users.freebasic-portal.de/stw/builds/
in file:
win32_mingw_additional_libs.zip

There's also "win64_mingw_additional_libs.zip" there, which contains a 64-bit version of libz.a
However, those binaries are those that shipped with the MinGW version that is used to compile those FreeBasic builds and are most likely outdated. I'd suggest to download the libz source code and compile it from source. That's very easy as libz does not depend on any other library.
For convenience a 32/64-bit build of the current libz version 1.2.11 can be downloaded from http://users.freebasic-portal.de/stw/fi ... b-1211.zip

//edit: sorry, I've mixed up libz and libzip; here's a libzip 32/64-bit build of version 1.2.0: http://users.freebasic-portal.de/stw/fi ... ip-120.zip
Note that libzip depends on libz, so you'll need to link both static libraries or provide both DLLs at runtime if using dynamic libraries.
MrSwiss
Posts: 3307
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: ZIP / UnZIP

Postby MrSwiss » May 29, 2017 10:11

@St_W,

thanks a lot, for the updated lib's (libz, libzip), for both FBC versions: 32/64.

Some quick test results (using the static lib's):
    Example libz: a Warning, that it's a "newer" version: 1.2.8, nothing more (works OK).
    (otherwise no problem at all, there where, it seems, no changes in functionality/interface)
    The example code was fixed, using: 'zip_t' and 'zip_file_t', unlike fxm's suggestion: 'Any Ptr'.
    Example libzip: 3 Errors, relating to crypto stuff (new functionality).
    This is as expected, because the (current) 'zip.bi' was made for ver.: 1.0.1. The new version is: 1.2.0.
Therefore, it is required to update 'zip.bi', to the new version ... have to look at it ... . Not yet working!
St_W
Posts: 1479
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: ZIP / UnZIP

Postby St_W » May 29, 2017 15:09

MrSwiss wrote:Example libzip: 3 Errors, relating to crypto stuff (new functionality).
This is as expected, because the (current) 'zip.bi' was made for ver.: 1.0.1. The new version is: 1.2.0.[/list]
Therefore, it is required to update 'zip.bi', to the new version ... have to look at it ... . Not yet working!

You may try http://users.freebasic-portal.de/stw/fi ... eaders.zip ... the headers have been generated by fbfrog, but I haven't tested them and the zip-header even still contains a TODO entry (as does the old header, interestingly). There haven't been a lot of changes between 1.0.1 and 1.2.0 so the old headers should actually work as long as no new features are being used, that were added after 1.0.1. Thus the compile/linking errors are a bit strange. There might also be an error in the library as it e.g. allows different compile configurations - maybe the default configuration, which I built, is somehow incompatible with the headers or example program?

@MrSwiss: if you're further digging into this maybe you could create patches for the compiler/bindings repo so that everyone could benefit from the fixes in the next FreeBasic version.
RoWa
Posts: 4
Joined: Dec 02, 2019 15:55

Re: ZIP / UnZIP

Postby RoWa » Dec 02, 2019 16:14

Here is an updated libzip.bi header file I made for the static libzip.a version 1.3.0. Hope without errors. Because I'm new in the forum I must look around, whether I can upload the libzip.a version 1.3.0 itself. The compiled library I found somewhere in the Internet and tested it until now with success.

However: Up to date is LibZip version 1.5.2.
Is anybody able to compile a static (!!!) library v1.5.2 using MinGW/MSYS for Win32 ?
I unfortunately don't have enough knowledge to do this.

Code: Select all

'FreeBasic include file for static libzip.a version 1.3.0
'Hand created by R.W., march 2018, tested with FreeBasic v1.0.6.0
'
'Copyright (C) for libzip 1999-2015 by Dieter Baron And Thomas Klausner
'The authors can be contacted at <libzip@nih.at>
'This file Is part of libzip, a library To manipulate ZIP archives.
'Redistribution And use in source And Binary forms, With Or without
'modification, are permitted provided that the following conditions
'are met:
'1. Redistributions of source code must retain the above copyright
'   notice, this list of conditions And the following disclaimer.
'2. Redistributions in Binary form must reproduce the above copyright
'   notice, this list of conditions And the following disclaimer in
'   the documentation And/Or other materials provided With the
'   distribution.
'3. The names of the authors may Not be used To endorse Or promote
'   products derived from this software without specific prior
'   written permission.
'
'THIS SOFTWARE Is PROVIDED BY THE AUTHORS ``As Is''AND ANY EXPRESS
'Or IMPLIED WARRANTIES, INCLUDING, BUT Not LIMITED To, THE IMPLIED
'WARRANTIES OF MERCHANTABILITY And FITNESS For A PARTICULAR PURPOSE
'ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE For Any
'DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, Or CONSEQUENTIAL
'DAMAGES (INCLUDING, BUT Not LIMITED To, PROCUREMENT OF SUBSTITUTE
'GOODS Or SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
'INTERRUPTION) HOWEVER CAUSED And On Any THEORY OF LIABILITY, WHETHER
'IN CONTRACT, STRICT LIABILITY, Or TORT (INCLUDING NEGLIGENCE Or
'OTHERWISE) ARISING IN Any WAY Out OF THE USE OF THIS SOFTWARE, EVEN
'If ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifndef _HAD_ZIP_BI
#define _HAD_ZIP_BI

#inclib "zip"
#inclib "z"                'At least when using a static libzip, zlib needs to be linked in too.

#include once "crt/stdio.bi"
#include once "crt/time.bi"
#include once "crt/stdint.bi"

Extern "c"

'<zipconf.bi>
#define LIBZIP_VERSION "1.3.0"
#define LIBZIP_VERSION_MAJOR 1
#define LIBZIP_VERSION_MINOR 3
#define LIBZIP_VERSION_MICRO 0

Type zip_int8_t As int8_t
#define ZIP_INT8_MIN INT8_MIN
#define ZIP_INT8_MAX INT8_MAX

Type zip_uint8_t As uint8_t
#define ZIP_UINT8_MAX UINT8_MAX

Type zip_int16_t As int16_t
#define ZIP_INT16_MIN INT16_MIN
#define ZIP_INT16_MAX INT16_MAX

Type zip_uint16_t As uint16_t
#define ZIP_UINT16_MAX UINT16_MAX

Type zip_int32_t As int32_t
#define ZIP_INT32_MIN INT32_MIN
#define ZIP_INT32_MAX INT32_MAX

Type zip_uint32_t As uint32_t
#define ZIP_UINT32_MAX UINT32_MAX

Type zip_int64_t As int64_t
#define ZIP_INT64_MIN INT64_MIN
#define ZIP_INT64_MAX INT64_MAX

Type zip_uint64_t As uint64_t
#define ZIP_UINT64_MAX UINT64_MAX
''</zipconf.bi>

'Flags for zip_open:
#define ZIP_CREATE           1
#define ZIP_EXCL             2
#define ZIP_CHECKCONS        4
#define ZIP_TRUNCATE         8
#define ZIP_RDONLY          16

'Flags for zip_name_locate, zip_fopen, zip_stat, ...:
#define ZIP_FL_NOCASE         1u 'ignore case on name lookup
#define ZIP_FL_NODIR          2u 'ignore directory component
#define ZIP_FL_COMPRESSED     4u 'read compressed data
#define ZIP_FL_UNCHANGED      8u 'use original data, ignoring changes
#define ZIP_FL_RECOMPRESS    16u 'force recompression of data
#define ZIP_FL_ENCRYPTED     32u 'read encrypted data (implies ZIP_FL_COMPRESSED)
#define ZIP_FL_ENC_GUESS      0u 'guess string encoding (is default)
#define ZIP_FL_ENC_RAW       64u 'get unmodified string
#define ZIP_FL_ENC_STRICT   128u 'follow specification strictly
#define ZIP_FL_LOCAL         256u 'in local header
#define ZIP_FL_CENTRAL       512u 'in central directory
'                          1024u  reserved for internal use
#define ZIP_FL_ENC_UTF_8   2048u 'string is UTF-8 encoded
#define ZIP_FL_ENC_CP437   4096u 'string is CP437 encoded
#define ZIP_FL_OVERWRITE   8192u 'zip_file_add: if file with name exists, overwrite (replace) it

'Archive global flags flags:
'#define ZIP_AFL_TORRENT    1u   'torrent zipped
#define ZIP_AFL_RDONLY      2u   'read only -- cannot be cleared

'Create a new extra field:
#define ZIP_EXTRA_FIELD_ALL   ZIP_UINT16_MAX
#define ZIP_EXTRA_FIELD_NEW   ZIP_UINT16_MAX

'Flags for compression and encryption sources:
#define ZIP_CODEC_ENCODE    1 'compress/encrypt

'libzip error codes:
#define ZIP_ER_OK             0  'N No error
#define ZIP_ER_MULTIDISK      1  'N Multi-disk zip archives not supported
#define ZIP_ER_RENAME         2  'S Renaming temporary file failed
#define ZIP_ER_CLOSE          3  'S Closing zip archive failed
#define ZIP_ER_SEEK           4  'S Seek error
#define ZIP_ER_READ           5  'S Read error
#define ZIP_ER_WRITE          6  'S Write error
#define ZIP_ER_CRC            7  'N CRC error
#define ZIP_ER_ZIPCLOSED      8  'N Containing zip archive was closed
#define ZIP_ER_NOENT          9  'N No such file
#define ZIP_ER_EXISTS        10  'N File already exists
#define ZIP_ER_OPEN          11  'S Can't open file
#define ZIP_ER_TMPOPEN       12  'S Failure to create temporary file
#define ZIP_ER_ZLIB          13  'Z Zlib error
#define ZIP_ER_MEMORY        14  'N Malloc failure
#define ZIP_ER_CHANGED       15  'N Entry has been changed
#define ZIP_ER_COMPNOTSUPP   16  'N Compression method not supported
#define ZIP_ER_EOF           17  'N Premature EOF
#define ZIP_ER_INVAL         18  'N Invalid argument
#define ZIP_ER_NOZIP         19  'N Not a zip archive
#define ZIP_ER_INTERNAL      20  'N Internal error
#define ZIP_ER_INCONS        21  'N Zip archive inconsistent
#define ZIP_ER_REMOVE        22  'S Can't remove file
#define ZIP_ER_DELETED       23  'N Entry has been deleted
#define ZIP_ER_ENCRNOTSUPP   24  'N Encryption method not supported
#define ZIP_ER_RDONLY        25  'N Read-only archive
#define ZIP_ER_NOPASSWD      26  'N No password provided
#define ZIP_ER_WRONGPASSWD   27  'N Wrong password provided
#define ZIP_ER_OPNOTSUPP     28  'N Operation not supported
#define ZIP_ER_INUSE         29  'N Resource still in use
#define ZIP_ER_TELL          30  'S Tell error

'type of system error value:
#define ZIP_ET_NONE       0      'sys_err unused
#define ZIP_ET_SYS        1      'sys_err is errno
#define ZIP_ET_ZLIB       2      'sys_err is zlib error code

'compression methods:
#define ZIP_CM_DEFAULT        -1  'better of deflate or store
#define ZIP_CM_STORE           0  'stored (uncompressed)
#define ZIP_CM_SHRINK          1  'shrunk
#define ZIP_CM_REDUCE_1        2  'reduced with factor 1
#define ZIP_CM_REDUCE_2        3  'reduced with factor 2
#define ZIP_CM_REDUCE_3        4  'reduced with factor 3
#define ZIP_CM_REDUCE_4        5  'reduced with factor 4
#define ZIP_CM_IMPLODE         6  'imploded
'                              7   Reserved for Tokenizing compression algorithm
#define ZIP_CM_DEFLATE         8  'deflated
#define ZIP_CM_DEFLATE64       9  'deflate64
#define ZIP_CM_PKWARE_IMPLODE 10  'PKWARE imploding
'                             11   Reserved by PKWARE
#define ZIP_CM_BZIP2          12  'compressed using BZIP2 algorithm
'                             13   Reserved by PKWARE
#define ZIP_CM_LZMA           14  'LZMA (EFS)
'                            15-17 Reserved by PKWARE
#define ZIP_CM_TERSE          18  'compressed using IBM TERSE (new)
#define ZIP_CM_LZ77           19  'IBM LZ77 z Architecture (PFS)
#define ZIP_CM_WAVPACK        97  'WavPack compressed data
#define ZIP_CM_PPMD           98  'PPMd version I, Rev 1

'encryption methods:
#define ZIP_EM_NONE            0  'not encrypted
#define ZIP_EM_TRAD_PKWARE     1  'traditional PKWARE encryption
#if 0                             'Strong Encryption Header not parsed yet
#define ZIP_EM_DES        &h6601  'strong encryption: DES
#define ZIP_EM_RC2_OLD    &h6602  'strong encryption: RC2, version < 5.2
#define ZIP_EM_3DES_168   &h6603
#define ZIP_EM_3DES_112   &h6609
#define ZIP_EM_AES_128    &h660e
#define ZIP_EM_AES_192    &h660f
#define ZIP_EM_AES_256    &h6610
#define ZIP_EM_RC2        &h6702  'strong encryption: RC2, version >= 5.2
#define ZIP_EM_RC4        &h6801
#endif
#define ZIP_EM_UNKNOWN    &hffff  'unknown algorithm

#define ZIP_OPSYS_DOS              &H00u
#define ZIP_OPSYS_AMIGA             &H01u
#define ZIP_OPSYS_OPENVMS         &H02u
#define ZIP_OPSYS_UNIX            &H03u
#define ZIP_OPSYS_VM_CMS         &H04u
#define ZIP_OPSYS_ATARI_ST       &H05u
#define ZIP_OPSYS_OS_2            &H06u
#define ZIP_OPSYS_MACINTOSH       &H07u
#define ZIP_OPSYS_Z_SYSTEM       &H08u
#define ZIP_OPSYS_CPM              &H09u
#define ZIP_OPSYS_WINDOWS_NTFS  &H0au
#define ZIP_OPSYS_MVS              &H0bu
#define ZIP_OPSYS_VSE              &H0cu
#define ZIP_OPSYS_ACORN_RISC     &H0du
#define ZIP_OPSYS_VFAT            &H0eu
#define ZIP_OPSYS_ALTERNATE_MVS   &H0fu
#define ZIP_OPSYS_BEOS            &H10u
#define ZIP_OPSYS_TANDEM         &H11u
#define ZIP_OPSYS_OS_400         &H12u
#define ZIP_OPSYS_OS_X            &H13u
#define ZIP_OPSYS_DEFAULT         ZIP_OPSYS_UNIX

Type zip_source_cmd As Long
Enum
  ZIP_SOURCE_OPEN_            'prepare for reading
  ZIP_SOURCE_READ_            'read data
  ZIP_SOURCE_CLOSE_           'reading is done
  ZIP_SOURCE_STAT_            'get meta information
  ZIP_SOURCE_ERROR_           'get error information
  ZIP_SOURCE_FREE_            'cleanup and free resources - TODO: name conflict with zip_source_free()
  ZIP_SOURCE_SEEK_            'set position for reading
  ZIP_SOURCE_TELL_            'get read position
  ZIP_SOURCE_BEGIN_WRITE_     'prepare for writing
  ZIP_SOURCE_COMMIT_WRITE_    'writing is done
  ZIP_SOURCE_ROLLBACK_WRITE_  'discard written changes
  ZIP_SOURCE_WRITE_           'write data
  ZIP_SOURCE_SEEK_WRITE_      'set position for writing
  ZIP_SOURCE_TELL_WRITE_      'get write position
  ZIP_SOURCE_SUPPORTS         'check whether source supports command
  ZIP_SOURCE_REMOVE           'remove file
End Enum

'#define ZIP_SOURCE_ERR_LOWER    -2

Type zip_source_cmd_t As zip_source_cmd

#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (1 Shl (cmd)) 'Alternative: #define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd)    (((zip_int64_t)1)<<(cmd))
#define ZIP_SOURCE_SUPPORTS_READABLE (((((ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_OPEN_) Or ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_READ_)) Or ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_CLOSE_)) Or ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_STAT_)) Or ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ERROR_)) Or ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_FREE_))
#define ZIP_SOURCE_SUPPORTS_SEEKABLE (((ZIP_SOURCE_SUPPORTS_READABLE Or ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK_)) Or ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL_)) Or ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SUPPORTS))
#define ZIP_SOURCE_SUPPORTS_WRITABLE (((((((ZIP_SOURCE_SUPPORTS_SEEKABLE Or ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_BEGIN_WRITE_)) Or ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_COMMIT_WRITE_)) Or ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ROLLBACK_WRITE_)) Or ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_WRITE_)) Or ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK_WRITE_)) Or ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL_WRITE_)) Or ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_REMOVE))

Type zip_source_args_seek  'for use by sources
   offset As zip_int64_t
   whence As Long
End Type

'ToDo:
'typedef struct zip_source_args_seek zip_source_args_seek_t;
'#define ZIP_SOURCE_GET_ARGS(type, data, len, error) ((len) < sizeof(type) ? zip_error_set((error), ZIP_ER_INVAL, 0), (type *)NULL : (type *)(data))

Type zip_error        'error information. use zip_error_*() to access
  zip_err As Long       'libzip error code (ZIP_ER_*)
  sys_err As Long     'copy of errno (E*) or zlib error code
  str As zstring Ptr  'string representation or NULL
End Type

#define ZIP_STAT_NAME               &h0001u
#define ZIP_STAT_INDEX_             &h0002u  'TODO: name conflict with zip_stat_index()
#define ZIP_STAT_SIZE               &h0004u
#define ZIP_STAT_COMP_SIZE          &h0008u
#define ZIP_STAT_MTIME              &h0010u
#define ZIP_STAT_CRC                &h0020u
#define ZIP_STAT_COMP_METHOD        &h0040u
#define ZIP_STAT_ENCRYPTION_METHOD  &h0080u
#define ZIP_STAT_FLAGS              &h0100u

Type zip_stat_
   valid As zip_uint64_t              'which fields have valid values
   Name As Const zstring Ptr          'name of the file
   index As zip_uint64_t              'index within archive
   size As zip_uint64_t               'size of file (uncompressed)
   comp_size As zip_uint64_t          'size of file (compressed)
   mtime As time_t                    'modification time
   crc As zip_uint32_t                'crc of file data
   comp_method As zip_uint16_t        'compression method used
   encryption_method As zip_uint16_t  'encryption method used
   flags As zip_uint32_t              'reserved for future use
End Type

Type zip_t As zip
Type zip_file As Any
Type zip_source As Any
Type zip_t As zip
Type zip_error_t As zip_error
Type zip_file_t As zip_file
Type zip_source_t As zip_source
Type zip_stat_t As zip_stat
Type zip_flags_t As zip_uint32_t

Type zip_source_callback As Function (ByVal As Any Ptr,ByVal As Any Ptr,ByVal As zip_uint64_t,ByVal As zip_source_cmd) As zip_int64_t

Declare Function zip_add(ByVal As zip_t Ptr,ByVal As Const zstring Ptr,ByVal As zip_source Ptr) As zip_int64_t                                  'deprecated in libzip 0.11, use zip_file_add()
Declare Function zip_add_dir(ByVal As zip_t Ptr,ByVal As Const zstring Ptr) As zip_int64_t                                                      'deprecated in libzip 0.11, use zip_dir_add()
Declare Function zip_archive_set_tempdir(ByVal As zip_t Ptr,ByVal As Const zstring Ptr) As Integer
Declare Function zip_close(ByVal As zip_t Ptr) As Integer
Declare Function zip_delete(ByVal As zip_t Ptr,ByVal As zip_uint64_t) As Integer
Declare Function zip_dir_add(ByVal As zip_t Ptr,ByVal As Const zstring Ptr,ByVal As Integer) As zip_int64_t
Declare Sub zip_discard(ByVal As zip_t Ptr)
Declare Sub zip_error_clear(ByVal As zip_t Ptr)
Declare Sub zip_error_get(ByVal As zip_t Ptr,ByVal As Integer Ptr,ByVal As Integer Ptr)                                                         'deprecated in libzip 1.0, use zip_file_get_error(), zip_error_code_zip(), / zip_error_code_system()
Declare Function zip_error_code_system(ByVal As Const zip_error_t Ptr) As Integer 'declare function zip_error_code_system(byval as const zip_error_t ptr) as long
Declare Function zip_error_code_zip(ByVal As Const zip_error_t Ptr) As Integer
Declare Sub zip_error_fini(ByVal As zip_error_t Ptr)
Declare Function zip_error_get_sys_type(ByVal As Integer) As Integer                                                                          'deprecated in libzip 1.0, use zip_error_system_type()
Declare Sub zip_error_init(ByVal As zip_error_t Ptr)
Declare Sub zip_error_init_with_code(ByVal As zip_error_t Ptr,ByVal As Integer)
Declare Sub zip_error_set(ByVal As zip_error_t Ptr,ByVal As Integer,ByVal As Integer)
Declare Function zip_error_strerror(ByVal As zip_error_t Ptr) As Const zstring Ptr
Declare Function zip_error_to_str(ByVal As UByte Ptr,ByVal As zip_uint64_t,ByVal As Integer,ByVal As Integer) As Integer                      'deprecated in libzip 1.0, use zip_error_init_with_code() and zip_error_strerror()
Declare Function zip_error_system_type(ByVal As Const zip_error_t Ptr) As Integer
Declare Function zip_file_get_error(ByVal As zip_file_t Ptr) As zip_error_t Ptr
Declare Function zip_get_error(ByVal As zip_t Ptr) As zip_error_t Ptr
Declare Function zip_source_error(ByVal As zip_source_t Ptr) As zip_error_t Ptr
Declare Function zip_error_to_data(ByVal As Const zip_error_t Ptr,ByVal As Any Ptr,ByVal As zip_uint64_t) As zip_int64_t
Declare Function zip_fclose(ByVal As zip_file_t Ptr) As Integer
Declare Function zip_fdopen(ByVal As Integer,ByVal As Integer,ByVal As Integer Ptr) As zip_t Ptr
Declare Function zip_file_add(ByVal As zip_t Ptr,ByVal As Const zstring Ptr,ByVal As zip_source_t Ptr,ByVal As Integer) As zip_int64_t
Declare Sub zip_file_error_clear(ByVal As zip_file_t Ptr)
Declare Sub zip_file_error_get(ByVal As zip_file_t Ptr,ByVal As Integer Ptr,ByVal As Integer Ptr)                                               'deprecated. Use zip_error_code_system(3), zip_error_code_zip(3), zip_file_get_error(3), and zip_get_error(3)
Declare Function zip_file_extra_field_delete(ByVal As zip_t Ptr,ByVal As zip_uint64_t,ByVal As zip_uint16_t,ByVal As Integer) As Integer
Declare Function zip_file_extra_field_delete_by_id(ByVal As zip_t Ptr,ByVal As zip_uint64_t,ByVal As zip_uint16_t,ByVal As zip_uint16_t,ByVal As Integer) As Integer
Declare Function zip_file_extra_field_get(ByVal As zip_t Ptr,ByVal As zip_uint64_t,ByVal As zip_uint16_t,BayVal As zip_uint16_t Ptr,ByVal As zip_uint16_t Ptr,ByVal As Integer) As zip_uint8_t Ptr
Declare Function zip_file_extra_field_get_by_id(ByVal As zip_t Ptr,ByVal As zip_uint64_t,ByVal As zip_uint16_t,ByVal As zip_uint16_t,ByVal As zip_uint16_t Ptr,ByVal As Integer) As zip_uint8_t Ptr
Declare Function zip_file_extra_field_set(ByVal As zip_t Ptr,ByVal As zip_uint64_t,ByVal As zip_uint16_t,ByVal As zip_uint16_t,ByVal As Const  zip_uint8_t Ptr,ByVal As zip_uint16_t,ByVal As Integer) As Integer
Declare Function zip_file_extra_fields_count(ByVal As zip_t Ptr,ByVal As zip_uint64_t,ByVal As Integer) As zip_int16_t
Declare Function zip_file_extra_fields_count_by_id(ByVal As zip_t Ptr,ByVal As zip_uint64_t,ByVal As zip_uint16_t,ByVal As Integer) As zip_int16_t
Declare Function zip_file_get_comment(ByVal As zip_t Ptr,ByVal As zip_uint64_t,ByVal As zip_uint32_t Ptr,ByVal As Integer) As Const zstring Ptr
Declare Function zip_file_get_external_attributes(ByVal As zip_t Ptr,ByVal As zip_uint64_t,ByVal As Integer,ByVal As zip_uint8_t Ptr,ByVal As zip_uint32_t Ptr) As Integer
Declare Function zip_file_rename(ByVal As zip_t Ptr,ByVal As zip_uint64_t,ByVal As Const zstring Ptr,ByVal As Integer) As Integer
Declare Function zip_file_replace(ByVal As zip_t Ptr,ByVal As zip_uint64_t,ByVal As zip_source_t Ptr,ByVal As Integer) As Integer
Declare Function zip_file_set_comment(ByVal As zip_t Ptr,ByVal As zip_uint64_t,ByVal As Const zstring Ptr,ByVal As zip_uint16_t,ByVal As Integer) As Integer
Declare Function zip_file_set_external_attributes(ByVal As zip_t Ptr,ByVal As zip_uint64_t,ByVal As Integer,ByVal As zip_uint8_t,ByVal As zip_uint32_t) As Integer
Declare Function zip_file_set_mtime(ByVal As zip_t Ptr,ByVal As zip_uint64_t,ByVal As time_t,ByVal As Integer) As Integer
Declare Function zip_file_strerror(ByVal As zip_file_t Ptr) As Const zstring Ptr
Declare Function zip_fopen(ByVal As zip_t Ptr,ByVal As Const zstring Ptr,ByVal As Integer) As zip_file_t Ptr
Declare Function zip_fopen_encrypted(ByVal As zip_t Ptr,ByVal As Const zstring Ptr,ByVal As Integer,ByVal As Const zstring Ptr) As zip_file_t Ptr
Declare Function zip_fopen_index(ByVal As zip_t Ptr,ByVal As zip_uint64_t,ByVal As Integer) As zip_file_t Ptr
Declare Function zip_fopen_index_encrypted(ByVal As zip_t Ptr,ByVal As zip_uint64_t,ByVal As Integer,ByVal As Const zstring Ptr) As zip_file_t Ptr
Declare Function zip_fread(ByVal As zip_file_t Ptr,ByVal As Any Ptr,ByVal As zip_uint64_t) As zip_int64_t
Declare Function zip_get_archive_comment(ByVal As zip_t Ptr,ByVal As Integer Ptr,ByVal As Integer) As Const zstring Ptr
Declare Function zip_get_file_comment(ByVal As zip_t Ptr,ByVal As zip_uint64_t,ByVal As Integer Ptr,ByVal As Integer) As Const zstring Ptr      'deprecated in libzip 0.11, use zip_file_get_comment()
Declare Function zip_get_file_extra(ByVal As zip_t Ptr,ByVal As zip_uint64_t,ByVal As Integer Ptr,ByVal As Integer) As Const zstring Ptr        'Old version of libzip.bi, doesn't exist (?)
Declare Function zip_get_archive_flag(ByVal As zip_t Ptr,ByVal As Integer,ByVal As Integer) As Integer
Declare Function zip_get_name(ByVal As zip_t Ptr,ByVal As zip_uint64_t,ByVal As Integer) As Const zstring Ptr
Declare Function zip_get_num_entries(ByVal As zip_t Ptr,ByVal As Integer) As zip_int64_t
Declare Function zip_get_num_files(ByVal As zip_t Ptr) As Integer                                                                               'deprecated in libzip 0.11, use zip_get_num_entries(instead)
Declare Function zip_name_locate(ByVal As zip_t Ptr,ByVal As Const zstring Ptr,ByVal As Integer) As zip_int64_t                                  'New version ToDo: Check!
'Declare Function zip_name_locate(ByVal As zip_t Ptr,ByVal As Const zstring Ptr,ByVal As Integer) As Integer                                     'Old version
Declare Function zip_open(ByVal As Const zstring Ptr,ByVal As Integer,ByVal As Integer Ptr) As zip_t Ptr
Declare Function zip_open_from_source(ByVal As zip_source_t Ptr,ByVal As Integer,ByVal As zip_error_t Ptr) As zip_t Ptr'Declare Function zip_rename(ByVal As zip_t Ptr,ByVal As zip_uint64_t,ByVal As Const zstring Ptr) As Integer                                     'deprecated in libzip 0.11, use zip_file_rename()
Declare Function zip_replace(ByVal As zip_t Ptr,ByVal As zip_uint64_t,ByVal As zip_source Ptr) As Integer                                       'deprecated, use zip_file_replace(3) with an empty flags argument
Declare Function zip_set_archive_comment(ByVal As zip_t Ptr,ByVal As Const zstring Ptr,ByVal As zip_uint16_t) As Integer                         'New version ToDo: Check!
'Declare Function zip_set_archive_comment(ByVal As zip_t Ptr,ByVal As Const UByte Ptr,ByVal As Integer) As Integer                               'Old version
Declare Function zip_set_archive_flag(ByVal As zip_t Ptr,ByVal As Integer,ByVal As Integer) As Integer
Declare Function zip_set_default_password(ByVal As zip_t Ptr,ByVal As Const zstring Ptr) As Integer
Declare Function zip_set_file_compression(ByVal As zip_t Ptr,ByVal As zip_uint64_t,ByVal As zip_int32_t,ByVal As zip_uint32_t) As Integer
Declare Function zip_set_file_comment(ByVal As zip_t Ptr,ByVal As zip_uint64_t,ByVal As Const UByte Ptr,ByVal As Integer) As Integer            'deprecated in libzip 0.11, use zip_file_set_comment()
'Declare Function zip_set_file_extra(ByVal As zip_t Ptr,ByVal As zip_uint64_t,ByVal As Const UByte Ptr,ByVal As Integer) As Integer              'Old version of libzip.bi, doesn't exist (?)
Declare Function zip_source_begin_write(ByVal As zip_source_t Ptr) As Long
Declare Function zip_source_buffer(ByVal As zip_t Ptr,ByVal As Const Any Ptr,ByVal As zip_uint64_t,ByVal As Integer) As zip_source_t Ptr
Declare Sub zip_source_buffer_create(ByVal As Const Any Ptr,ByVal As zip_uint64_t,ByVal As Integer,ByVal As zip_error_t Ptr)
Declare Function zip_source_close(ByVal As zip_source_t Ptr) As Integer
Declare Function zip_source_commit_write(ByVal As zip_source_t Ptr) As Integer
Declare Sub zip_source_file(ByVal As zip_t Ptr,ByVal As Const zstring Ptr,ByVal As zip_uint64_t,ByVal As zip_int64_t)                      'New version ToDo: Check!
'Declare Function zip_source_file(ByVal As zip_t Ptr,ByVal As Const zstring Ptr,ByVal As zip_uint64_t,ByVal As zip_int64_t) As zip_source Ptr    'Old version
Declare Sub zip_source_file_create(ByVal As Const zstring Ptr,ByVal As zip_uint64_t,ByVal As zip_int64_t,ByVal As zip_error_t Ptr)
Declare Sub zip_source_filep(ByVal As zip_t Ptr,ByVal As Any Ptr,ByVal As zip_uint64_t,ByVal As zip_int64_t)                               'New version ToDo: Check!
'Declare Function zip_source_filep(ByVal As zip_t Ptr,ByVal As FILE Ptr,ByVal As zip_uint64_t,ByVal As zip_int64_t) As zip_source Ptr            'Old version
Declare Sub zip_source_filep_create(ByVal As Any Ptr,ByVal As zip_uint64_t,ByVal As zip_int64_t,ByVal As zip_error_t Ptr)
Declare Sub zip_source_free(ByVal As zip_source_t Ptr)
Declare Sub zip_source_function(ByVal As zip_t Ptr,ByVal As zip_source_callback,ByVal As Any Ptr)                                          'New version ToDo: Check!
'Declare Function zip_source_function(ByVal As zip_t Ptr,ByVal As zip_source_callback,ByVal As Any Ptr) As zip_source Ptr                        'Old version
Declare Function zip_source_function_create(ByVal As zip_source_callback,ByVal As Any Ptr,ByVal As zip_error_t Ptr) As zip_source_t Ptr
Declare Function zip_source_is_deleted(ByVal As zip_source_t Ptr) As Integer
Declare Sub zip_source_keep(ByVal As zip_source_t Ptr)
'Declare Function zip_source_make_command_bitmap(zip_source_cmd_t,...) As zip_int64_t  'ToDo - c: ZIP_EXTERN zip_int64_t zip_source_make_command_bitmap(zip_source_cmd_t,...);
Declare Function zip_source_open(ByVal As zip_source_t Ptr) As Integer
Declare Function zip_source_read(ByVal As zip_source_t Ptr,ByVal As Any Ptr,ByVal As zip_uint64_t) As zip_int64_t
Declare Sub zip_source_rollback_write(ByVal As zip_source_t Ptr)
Declare Function zip_source_seek(ByVal As zip_source_t Ptr,ByVal As zip_int64_t,ByVal As Integer) As Integer
Declare Function zip_source_seek_compute_offset(ByVal As zip_uint64_t,ByVal As zip_uint64_t,ByVal As Any Ptr,ByVal As zip_uint64_t,ByVal As zip_error_t Ptr) As zip_int64_t
Declare Function zip_source_seek_write(ByVal As zip_source_t Ptr,ByVal As zip_int64_t,ByVal As Integer) As Integer
Declare Function zip_source_stat(ByVal As zip_source_t Ptr,ByVal As zip_stat_ Ptr) As Integer
Declare Function zip_source_tell(ByVal As zip_source_t Ptr) As zip_int64_t
Declare Function zip_source_tell_write(ByVal As zip_source_t Ptr) As zip_int64_t
Declare Function zip_source_write(ByVal As zip_source_t Ptr,ByVal As Const Any Ptr,ByVal As zip_uint64_t) As zip_int64_t
Declare Function zip_source_zip(ByVal As zip_t Ptr,ByVal As zip_t Ptr,ByVal As zip_uint64_t,ByVal As zip_flags_t,ByVal As zip_uint64_t,ByVal As zip_int64_t) As zip_source_t Ptr
'Declare Function zip_source_zip(ByVal As zip_t Ptr,ByVal As zip_t Ptr,ByVal As zip_uint64_t,ByVal As Integer,ByVal As zip_uint64_t,ByVal As zip_int64_t) As zip_source Ptr  'Old version
Declare Function zip_stat(ByVal As zip_t Ptr,ByVal As Const zstring Ptr,ByVal As Integer,ByVal As zip_stat_ Ptr) As Integer
Declare Function zip_stat_index(ByVal As zip_t Ptr,ByVal As zip_uint64_t,ByVal As Integer,ByVal As zip_stat_ Ptr) As Integer
Declare Sub zip_stat_init(ByVal As zip_stat_ Ptr)
Declare Function zip_strerror(ByVal As zip_t Ptr) As Const zstring Ptr
Declare Function zip_unchange(ByVal As zip_t Ptr,ByVal As zip_uint64_t) As Integer
Declare Function zip_unchange_all(ByVal As zip_t Ptr) As Integer
Declare Function zip_unchange_archive(ByVal As zip_t Ptr) As Integer

#ifdef __FB_WIN32__
Declare Function zip_source_win32a(ByVal As zip_t Ptr, ByVal As Const zstring Ptr, ByVal As zip_uint64_t, ByVal As zip_int64_t) As zip_source_t Ptr
Declare Function zip_source_win32a_create(ByVal As Const zstring Ptr, ByVal As zip_uint64_t, ByVal As zip_int64_t, ByVal As zip_error_t Ptr) As zip_source_t Ptr
Declare Function zip_source_win32handle(ByVal As zip_t Ptr, ByVal As Any Ptr, ByVal As zip_uint64_t, ByVal As zip_int64_t) As zip_source_t Ptr
Declare Function zip_source_win32handle_create(ByVal As Any Ptr, ByVal As zip_uint64_t, ByVal As zip_int64_t, ByVal As zip_error_t Ptr) As zip_source_t Ptr
Declare Function zip_source_win32w(ByVal As zip_t Ptr, ByVal As Const wstring Ptr, ByVal As zip_uint64_t, ByVal As zip_int64_t) As zip_source_t Ptr
Declare Function zip_source_win32w_create(ByVal As Const wstring Ptr, ByVal As zip_uint64_t, ByVal As zip_int64_t, ByVal As zip_error_t Ptr) As zip_source_t Ptr
#endif

End Extern

#endif
Last edited by RoWa on Dec 02, 2019 19:45, edited 3 times in total.
RoWa
Posts: 4
Joined: Dec 02, 2019 15:55

Re: ZIP / UnZIP

Postby RoWa » Dec 02, 2019 16:18

Here is an UnZip example by me, able to handle Unicode and special characters such as german Umlauts.

Code: Select all

'FreeBasic UnZip example using LibZip static library (linked into the own executable) with Unicode characters
'see http://www.nih.at/libzip/
'see http://libzip.org/documentation/libzip.html
'see http://www.freebasic.net/wiki/wikka.php?wakka=ExtLibZip
'************************************************************************************************************************
#include Once "windows.bi"
#include Once "LibZip.bi"     'ZIP archives library.
#define UNICODE
'************************************************************************************************************************
Dim i As Integer,j As Integer,k As Integer
Dim swArchiveToLoad As Wstring*MAX_PATH,swFileToLoad As wString*MAX_PATH
Dim pszFileNameUTF8 As Const zString Ptr,szFileNameUTF8 As zString*MAX_PATH,swFileName As wString*MAX_PATH
Dim sBuffer As String,szBuffer As zString*32768,iLenFile As Long
Dim pZipArchive As Any Ptr,pZipFile As Any Ptr,ZipStat As zip_stat_
'
swArchiveToLoad="testfile.zip"                            '
'swFileToLoad="test.txt"                                   '
swFileToLoad="File with long name and umlauts ÄÖÜß.txt" 'File to extract from zip archive

pZipArchive=zip_open(swArchiveToLoad,ZIP_RDONLY,@i)
If (i<>NULL) Then
  MessageBox(NULL,"Could not open "+swArchiveToLoad,"Error "+Str(i),MB_ICONSTOP)
Else
  i=zip_get_num_entries(pZipArchive,NULL) 'ZIP_FL_UNCHANGED
  'j=zip_libzip_version()  'new in libzip v1.3.1
  j=0
  sBuffer=""
  Do
    pszFileNameUTF8=zip_get_name(pZipArchive,j,ZIP_FL_ENC_GUESS)       'Get filename in UTF-8 format
    If pszFileNameUTF8=NULL Then Exit Do
    k=MultiByteToWideChar(CP_UTF8,0,pszFileNameUTF8,-1,swFileName,SizeOf(swFileName)) 'Convert UTF-8 filename into 16-bit Unicode
    sBuffer=sBuffer+Str(k)+" bytes: "+Left(swFileName,k)+Chr(13)         '
    j=j+1
  Loop
  '
  WideCharToMultiByte(CP_UTF8,0,ByVal Cast(LPCWSTR,SAdd(swFileToLoad)),-1,szFileNameUTF8,SizeOf(szFileNameUTF8),ByVal NULL,ByVal NULL)    'Convert filename to UTF-8
  zip_stat(pZipArchive,szFileNameUTF8,ZIP_STAT_NAME Or ZIP_STAT_SIZE Or ZIP_STAT_COMP_SIZE Or ZIP_STAT_COMP_METHOD Or ZIP_STAT_ENCRYPTION_METHOD,@ZipStat)
  sBuffer="Filename (UTF-8 format): "+*ZipStat.name+Chr(13)+_
          "File size: "+Str(ZipStat.size)+Chr(13)+_
          "Compressed size:"+Str(ZipStat.comp_size)+Chr(13)+_
          "Compression method: "+Str(ZipStat.comp_method)+Chr(13)+_
          "Encryption method: "+Str(ZipStat.encryption_method)
          'Further type members not used here: ZipStat.valid, ZipStat.index, ZipStat.mtime, ZipStat.crc, ZipStat.flags
  '
  pZipFile=zip_fopen(pZipArchive,szFileNameUTF8,0)
  If (pZipFile=NULL) Then
    MessageBox(NULL,"Could not open file"+Chr(13)+szFileNameUTF8+Chr(13)+"in archive "+swArchiveToLoad,"Error "+Str(@pZipArchive),MB_ICONSTOP)
  Else
    iLenFile=zip_fread(pZipFile,SAdd(szBuffer),SizeOf(szBuffer))
    MessageBox(NULL,"File content:"+Chr(13,13,13)+szBuffer+Chr(13,13,13)+sBuffer,"File size of "+szFileNameUTF8+": "+Str(iLenFile)+" Bytes",NULL)
    '
    zip_fclose(pZipFile)
  End If
  zip_close(pZipArchive)
End If 
Last edited by RoWa on Dec 02, 2019 19:40, edited 1 time in total.
srvaldez
Posts: 2160
Joined: Sep 25, 2005 21:54

Re: ZIP / UnZIP

Postby srvaldez » Dec 02, 2019 22:32

RoWa wrote:However: Up to date is LibZip version 1.5.2.
Is anybody able to compile a static (!!!) library v1.5.2 using MinGW/MSYS for Win32 ?

probably could be done, but it's not as simple as configuring and making because it uses CMake.
RoWa
Posts: 4
Joined: Dec 02, 2019 15:55

Re: ZIP / UnZIP

Postby RoWa » Dec 03, 2019 14:05

@srvaldez: Whould be great! :-)
If done, I look over the include files and could made some further example files.

It whould be a good idea, to give the official FreeBasic distribution an updated LibZip version
srvaldez
Posts: 2160
Joined: Sep 25, 2005 21:54

Re: ZIP / UnZIP

Postby srvaldez » Dec 03, 2019 14:28

@RoWa
I have disappointing news for you, libzip has like half a dozen or more dependencies and it would take more know-how than what I got to build a static lib or even a DLL
one can install a static libzip in msys2 but the dependencies are still there
RoWa
Posts: 4
Joined: Dec 02, 2019 15:55

Re: ZIP / UnZIP

Postby RoWa » Dec 05, 2019 14:03

Anyway Thank You! - 5 Minutes ago I made a found, which evenbtually can help:
http://www.wittfella.com/openssl
There's a Zip containing the include folder and libssl.a and libcrypto.a static libraries created for Windows 32bit using MinGW compiler.

Let's see...

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 1 guest