[Gambas-user] Help for observ one process...

vuott at tutanota.com vuott at tutanota.com
Fri May 19 13:15:33 CEST 2023


...maybe by using libzip external functions:

[code]
Private Const ZIP As String =  "/path/of/my_file.zip"Private Const UNZIP As String = "/folder/of/uncompressed/files"
Private entries As Long
Private z As Pointer

Library "libzip"

Public Struct zip_stat
  valid As Long
  name As Pointer
  index As Long
  size As Long
  comp_size As Long
  mtime As Long
  crc As Integer
  comp_method As Short
  encryption_method As Short
  flags As Integer
End Struct

' struct zip *zip_open(const char *, int, int *)
' Open zip archive.
Private Extern zip_open(path As String, flags As Integer, errorp As Pointer) As Pointer

' zip_int64_t zip_get_num_entries(zip_t *, zip_flags_t)
' Get number of files in archive.
Private Extern zip_get_num_entries(archive As Pointer, flags As Integer) As Long

' int zip_stat_index(struct zip *, int, int, struct zip_stat *)
' Get information about file by index.
Private Extern zip_stat_index(archive As Pointer, index As Integer, flags As Integer, sb As Zip_stat) As Integer

' struct zip_file * zip_fopen_index(struct zip *, int, int)
' Open file in zip archive for reading by index
Private Extern zip_fopen_index(archive As Pointer, index As Integer, flags As Integer) As Pointer

' zip_int64_t zip_fread(struct zip_file *, void *, zip_uint64_t)
' Read from file.
Private Extern zip_fread(zfile As Pointer, buf As Byte[], nbytes As Long) As Long

' int zip_fclose(struct zip_file *)
' Close file in zip archive.
Private Extern zip_fclose(zfile As Pointer) As Integer

' int zip_close(struct zip *)
' Close zip archive.
Private Extern zip_close(archive As Pointer) As Integer


Public Sub Form_Open()

  z = zip_open(ZIP, 0, 0)
  If z == 0 Then
    zip_close(z)
    Error.Raise("Error !")
  Endif
 
  entries = zip_get_num_entries(z, 0)
  Print "Number of files to decompress: "; entries

End

Public Sub Button1_Click()

  Dim zf As Pointer
  Dim i, ln As Integer
  Dim zsname As String
  Dim zs As New Zip_stat
  Dim l As Long
  Dim fl As File
  Dim buf As New Byte[64]
  
  For i = 0 To entries - 1
   If zip_stat_index(z, i, 0, zs) = 0 Then
     zsname = String@(zs.name)
     Print gb.NewLine; i + 1
     Print "Name:       "; zsname
     Print "Size: "; zs.size; " byte"
     If Right(zsname, 1) = "/" Then
       Continue
     Else
       zf = zip_fopen_index(z, i, 0)
       If zf == 0 Then
         zip_fclose(zf)
         Error.Raise("Error !")
       Endif
       fl = Open UNZIP &/ File.Name(zsname) For Create
       l = 0
       While l < zs.size
         ln = zip_fread(zf, buf, 64)
         If ln < 0 Then Error.Raise("Error !")
         buf.Write(fl, 0, ln)
         l += ln
       Wend
       fl.Close
       zip_fclose(zf)
     Endif
   Endif       
   ProgressBar1.Value = (i + 1) / entries
   Wait 0.3
Next
  
zip_close(z)

End
[/code]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20230519/295dc7f2/attachment.htm>


More information about the User mailing list