B4A Library [Lib] Archiver

By courtesy of Djembefola, this library is released as freeware for the benefit of the community. You should send him a big "thank you".

This library provides a basic support for Zip, Tar and Gzip archives (including TarGz). It can compress/uncompress synchronously or asynchronously (one task in the background at a time). This lib doesn't support encryption (but you can use it with encrypted files).

Its use is fairly simple. Examples:
B4X:
Dim Arc As Archiver

Arc.Gzip(File.DirRootExternal, "test2.tar", File.DirRootExternal)
Arc.UnGzip(File.DirRootExternal, "test2.tar.gz", File.DirRootExternal & "/testTARgz2")
Arc.AsyncGzip(File.DirRootExternal & "/media/image", "test.jpg", File.DirRootExternal, "Arc")

Dim m As Map
Try
   m = Arc.ListZipEntries(File.DirRootExternal & "/media/image/Icones", "android-icons.zip")
   For i = 0 To m.Size - 1
      Dim Info(3) As Long
      Info = m.GetValueAt(i)
      Log(m.GetKeyAt(i))
      Log("   Uncompressed size = " & Info(0))
      Log("   Compressed size = " & Info(1))
      Log("   CRC = " & Info(2))
   Next
Catch
   Log(LastException.Message)
End Try

This library is provided as-is and will not be extended to other formats. It uses the JTar library.

Don't forget to credit the authors if you include it in your application:
Frédéric Leneuf-Magaud & Kamran Zafar

v1.11:
I improved the synchronization of asynchronous operations (Async orders can be enqueued now);
The event declarations appear now with Space+Tab in the IDE.*

There's an improved version of this library for Zip files in my ProBundle that supports encryption and decryption.
 

Attachments

  • Archiver v1.11.zip
    26.4 KB · Views: 4,063
Last edited:

GabrielM

Member
Licensed User
Longtime User
Thank you Djembefola for your generosity! :icon_clap:
Much Appreciated .
 

moster67

Expert
Licensed User
Longtime User
A BIG thank you Djembefola! Most kind of you.

...and thanks to Fred for implementing it.
 

AscySoft

Active Member
Licensed User
Longtime User
Why do you work with string array and not just simple with List?

I mean the "InFileNames()" parameter from Archive.ZipFiles is an array of string. In my real life scenario to create an unknow array size is hard(like archive all files in a folder matching a "*.txt" mask...)
It requires (as my current understanding) a lot of work in code.
 

Informatix

Expert
Licensed User
Longtime User
Why do you work with string array and not just simple with List?

To create a List, you have to do:
1) Dim L as List
2) L.Initialize
For i = 1 to NbOfFiles
L.Add(...)
Next

To create a dynamic array of strings, you have to do:
1) Dim myArray() As String
2) Dim myArray(NbOfFiles) As String
For i = 1 to NbOfFiles
myArray(i-1) = ...
Next

I can't see a real advantage for the List here.
 

AscySoft

Active Member
Licensed User
Longtime User
To create a List, you have to do:
1) Dim L as List
2) L.Initialize
For i = 1 to NbOfFiles
L.Add(...)
Next

To create a dynamic array of strings, you have to do:
1) Dim myArray() As String
2) Dim myArray(NbOfFiles) As String
For i = 1 to NbOfFiles
myArray(i-1) = ...
Next

I can't see a real advantage for the List here.

That's seams correct, but if you don't know the NbOfFiles, with List is easy
1)dim L as List
2) L.Initialize
3) L=File.ListFiles("in a folder")

then.. later on, with L you could do all kind of stuff, sorting, removing, adding, testing , but not easily done with an array object.

Ok, maybe in the scope of your library this was not the case, but please be gentle and advise me on a real situation

HOW to zip all files matching "*.txt" mask from a folder using ZipFiles and not ZipFolder?
 
Last edited:

Informatix

Expert
Licensed User
Longtime User
That's seams correct, but if you don't know the NbOfFiles, with List is easy

To be honest, I don't remember why I chose an array instead of a list. Probably that suited better my code.

HOW to zip all files matching "*.txt" mask from a folder using ZipFiles and not ZipFolder?

Since your question is not related to Archiver, you should ask it in the "Updates & Question" forum because my time is very limited. I wrote a class, File Explorer, that may help you to understand how to retrieve a list of files.
 

upsis

Member
Licensed User
Longtime User
Crc

Excuse my ignorance, but how do I know if the CRC in ListZipEntries is ok? Thanks in advance.
 
Top