B4A Library SD: ZipLibrary

SD_ZipLibray

Author:
Star-Dust
Version: 1.03
  • SD_ZipLibrary
    • Event
      • finish (Success as Boolean)
    • Functions:
      • Class_Globals As String
      • Initialize (CallBack As Object, EventName As String) As String
        Initializes the object. You can add parameters to this method if needed.
      • IsInitialized As Boolean
        Verifica se l'oggetto sia stato inizializzato.
      • unZip (FileZip As String, OutPutFolder As String) As String
      • unZipList (FileZip As String) As List
      • Zip (FilesTxt As String(), FileZip As String) As String

SD_ZipLibray

Author:
Star-Dust
Version: 1.03
  • SD_ZipLibrary
    • Event
      • finish (Success as Boolean)
    • Functions:
      • Class_Globals As String
      • Initialize (CallBack As Object, EventName As String) As String
        Initializes the object. You can add parameters to this method if needed.
      • IsInitialized As Boolean
        Verifica se l'oggetto sia stato inizializzato.
      • unZip (FileZip As String, OutPutFolder As String) As String
      • unZipList (FileZip As String) As List
      • Zip (FilesTxt As String(), FileZip As String) As String

List file in to Zip
B4X:
Dim UZ As SD_ZipLibrary

    UZ.Initialize
    Log("File: " & File.Exists(File.DirRootExternal,fileZipName))
    Dim L As List = UZ.unZipList(File.Combine(File.DirRootExternal,fileZipName))

Unzip
B4X:
Dim UZ As SD_ZipLibrary

UZ.Initialize
    UZ.unZip(File.Combine(File.DirRootExternal,fileZipName),File.Combine(File.DirRootExternal,DestinationPath))


Zip files
B4X:
Dim ZL As SD_ZipLibray
Dim ListFiles as List

ZL.Initialize(Me,"ZL")
ZL.Zip(ListFiles,ZipFileName)

Wait For
B4X:
Dim UZ As SD_ZipLibrary

UZ.Initialize
Log("File: " & File.Exists(File.DirRootExternal,fileZipName))
Dim L As List = UZ.unZipList(File.Combine(File.DirRootExternal,fileZipName))

Wait For UZ_finish(Success As Boolean)
Log("result:" &Success)
Log("Num: " & L.Size)
 

Attachments

  • SD_ZipLibray 0.13.zip
    3.9 KB · Views: 524
  • SD_ZipLibrary.bas
    4.8 KB · Views: 327
Last edited:

JohnC

Expert
Licensed User
Longtime User
try it like this
B4X:
Zip.Initialize(Me,"Zip")
Zip.Zip(ArrayofFiles, File.Combine(ZipFileDirectory,ZipFileName))
Wait For Zip_Finish(Success As Boolean)
' or
'Wait For (Zip) Zip_Finish(Success As Boolean)
Unfortunately, neither one worked - the code flow just stops at the Wait For line indefinately
 

Star-Dust

Expert
Licensed User
I can't seem to figure out how I can eliminate the separate ZL_Finish sub and simply use a "Wait For".

I tried the below, but the code just hangs:
B4X:
Zip.Initialize(Me,"Zip")
Zip.Zip(ArrayofFiles, File.Combine(ZipFileDirectory,ZipFileName))
Wait For (Zip) Finish(Success As Boolean)

Anyone have any suggestions?
In effect it does not work, it raises the event but is not intercepted by the wait FOR.

I have to study on it and then let you know
 

JohnC

Expert
Licensed User
Longtime User

ilan

Expert
Licensed User
Longtime User
Can you send me an example to illustrate this statement? My current device has Android 8. It will be easy to test.

hi @Informatix, it was an old post. actually i am using ArchiverPlus Lib in my apps after you have guided me on how to fix that crash. my mistake was that i performed actions in the finished event of the archiverplus lib and after putting the code in a different sub and calling it from the finished event with CallSubDelayed() function it is working fine.
 
Last edited:

Star-Dust

Expert
Licensed User
Can you send me an example to illustrate this statement? My current device has Android 8. It will be easy to test.
hi @Informatix, it was an old post. actually i am using ArchiverPlus Lib in my apps after you have guided me on how to fix that crash. my mistake was that i performed actions in the finished event of the archiverplus lib and after putting the code in a different sub and calling it from the finished event with callsub() function it is working fine.
This is OT

It would be better if you talked about the ArchivePlus library in the thread related to this library.

Each thread has an argument or title and in post must be related to that and not to other library topics.

This confuses users looking for an answer and expects to find it in thread that carries the correct title and related to the topic.

Talking about a library with a thread dedicated to another library is an incorrect practice
 

ilan

Expert
Licensed User
Longtime User
This is OT

It would be better if you talked about the ArchivePlus library in the thread related to this library.

Each thread has an argument or title and in post must be related to that and not to other library topics.

This confuses users looking for an answer and expects to find it in thread that carries the correct title and related to the topic.

Talking about a library with a thread dedicated to another library is an incorrect practice

first, i am not trying to start an argument here BUT if you will look at @Informatix profile and on mine you will see that we are here quite a while (since 2012) so i dont think your response is required in this case. Fred asked a legitime question after i posted that his lib is crashing. so how can he response in a different thread if the question was asked here? i really think that all those responses where users think they have the right to tell others how to behave in this forum is annoying. i miss those days where we could ask questions without thinking 10 times if this is the right place to do that or getting disrespect. this situation is preventing me from asking questions and this is why i am much less active today. in the past, i had much more fun in this forum. very sad! i guess if @Erel is not stopping it he agrees with it and thats also sad. last time i checked only erel was the Administrator but sometimes it looks like we have more then 1 admin here.
 

Star-Dust

Expert
Licensed User
The question is not who administrates forums, Erel or others. The question is respect for rules and for people.
I opened this thread for a purpose and it would be answered in my regard that it remained so.

Is regard towards Erel who is hosting us to respect his rules, regardless of whether he intervenes or not.

I highly value your work and you as a person. I am sure that since you have been attending this forum for 7 years, much more than me, you will want to set an example in respecting the rules.

We do not need a moderator to enforce the rules, nor a user who is there to remember, we are adults.
 
Last edited:

ilan

Expert
Licensed User
Longtime User
.................

i have a lot to say but i already see that it will not make any difference. the good spirit of this forum has changed long time ago by few members and they decide how this forum runs (this is how it looks to me). although it is the first time i see you responding like this. anyway, have a nice evening.

(i will change my signature from now to:
"Sometimes our power resides not in what we say but in what we don't say.")
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Ilan, I don't think that you were disrespected. Star-Dust wrote a library which he cares about and this is indeed not the place to discuss an issue about a different, similar library.

The forum "rules" are quite simple and nothing bad happens if you don't strictly follow them. In the worst case you will be asked to start a new thread for the discussion.
 

Star-Dust

Expert
Licensed User
Unfortunately, neither one worked - the code flow just stops at the Wait For line indefinately
The correct code is the one suggested by @DonManfred
B4X:
Zip.Initialize(Me,"Zip")
Zip.Zip(ArrayofFiles, File.Combine(ZipFileDirectory,ZipFileName))
Wait For Zip_finish(Success As Boolean)

But I have observed that it does not always work, sometimes the event is consumed so quickly that it is not intercepted by wait for, which remains on hold.

I could see that the UZ_finish event is always raised
 

Star-Dust

Expert
Licensed User
How are you raising the event? It will not happen if you use ba.raiseEventFromDifferentThread.
I use
B4X:
CallSub3(mCallBack, EvName, param1, param2)
As you know even if in some parts I use Java, I try to use B4X as much as possible
 

Star-Dust

Expert
Licensed User
Thanks to @Erel's suggestion, it is now working correctly.

I updated to version 1.03 and the wait for will be used as in the example below
B4X:
Dim UZ As SD_ZipLibrary
UZ.Initialize
Log("File: " & File.Exists(File.DirRootExternal,fileZipName))
Dim L As List = UZ.unZipList(File.Combine(File.DirRootExternal,fileZipName))

Wait For UZ_finish(Success As Boolean)
Log("result:" &Success)
Log("Num: " & L.Size)
 

yfleury

Active Member
Licensed User
Longtime User
HI,
I try to zip 10 jpg files but it fail.
The zip file was create but is empty and the result of waitfor is "zip fail"
The jpg files is in VideoFileDir

I use this
B4X:
    Dim ZL As SD_ZipLibrary
    Dim  zipfilename As String
    DateTime.DateFormat ="yyyy_MM_dd"
    If listePhotosEnregistrer.Size > 0 Then
        ZL.Initialize(Me,"ZL")
        zipfilename=File.Combine(VideoFileDir,  DateTime.Date(DateTime.Now) & "_" & DateTime.Time(DateTime.Now) & ".zip")
        ZL.Zip(ListToArray(listePhotosEnregistrer),zipfilename)
        Wait For (ZL) ZL_finish(Success As Boolean)
        If Success Then
            Log("zip ok ")
        Else
            Log ("zip fail")
        End If
    End If
 

Star-Dust

Expert
Licensed User
HI,
I try to zip 10 jpg files but it fail.
The zip file was create but is empty and the result of waitfor is "zip fail"
The jpg files is in VideoFileDir

I use this
B4X:
    Dim ZL As SD_ZipLibrary
    Dim  zipfilename As String
    DateTime.DateFormat ="yyyy_MM_dd"
    If listePhotosEnregistrer.Size > 0 Then
        ZL.Initialize(Me,"ZL")
        zipfilename=File.Combine(VideoFileDir,  DateTime.Date(DateTime.Now) & "_" & DateTime.Time(DateTime.Now) & ".zip")
        ZL.Zip(ListToArray(listePhotosEnregistrer),zipfilename)
        Wait For (ZL) ZL_finish(Success As Boolean)
        If Success Then
            Log("zip ok ")
        Else
            Log ("zip fail")
        End If
    End If
It could depend on the destination folder that requires storage permissions or on the files you want to compress.
 

yfleury

Active Member
Licensed User
Longtime User
It could depend on the destination folder that requires storage permissions or on the files you want to compress.
I can add jpg files and zip can create (but empty) on same folder. I will test it on DirInternal
 

Star-Dust

Expert
Licensed User
NEW
I decided to make public the code with which I written this library. Use some java code, I think it can help the community understand how to use java (I know very little about it) inside b4x and maybe develop their own libraries.

Find the .BAS file with the source at the first post
 
Last edited:
Top