B4A Library [Lib] Archiver

Discussion in 'Additional libraries, classes and official updates' started by Informatix, Sep 26, 2012.

  1. Informatix

    Informatix Expert Licensed User

    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:
    Dim Arc As Archiver

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

    Dim m As Map
       m = Arc.ListZipEntries(
    File.DirRootExternal & "/media/image/Icones""android-icons.zip")
    For i = 0 To m.Size - 1
    Dim Info(3As Long
          Info = m.GetValueAt(i)
    Log("   Uncompressed size = " & Info(0))
    Log("   Compressed size = " & Info(1))
    Log("   CRC = " & Info(2))
    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

    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.

    Attached Files:

    Last edited: Oct 1, 2015
  2. NJDude

    NJDude Expert Licensed User

    A BIG thank you to both of you.
    victormedranop likes this.
  3. JonPM

    JonPM Well-Known Member Licensed User

    Finally! thanks
  4. GabrielM

    GabrielM Member Licensed User

    Thank you Djembefola for your generosity! :icon_clap:
    Much Appreciated .
  5. moster67

    moster67 Expert Licensed User

    A BIG thank you Djembefola! Most kind of you.

    ...and thanks to Fred for implementing it.
    Kwame Twum likes this.
  6. Erel

    Erel Administrator Staff Member Licensed User

  7. dealsmonkey

    dealsmonkey Active Member Licensed User

    Many thanks, much appreciated.
  8. giga

    giga Well-Known Member Licensed User

    :sign0098: Djembefola

    GREAT Library.. Thanks for your contribution. :icon_clap:
  9. vecino

    vecino Well-Known Member Licensed User

    thank you very much
  10. AscySoft

    AscySoft Active Member Licensed User

    Small question: how can I archive only a folder content and not including folder name in resulting archive? (I've test it with zip, currently replacing ABZipUnZip library wich have a known bug)
  11. Informatix

    Informatix Expert Licensed User

    You archive all the files of this folder with ZipFiles.
  12. AscySoft

    AscySoft Active Member Licensed User

    Mai, c'est logique! Silly me :))

    {I was roughly replacing my previous code without thinking at all the opportunities}
  13. AscySoft

    AscySoft Active Member Licensed 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.
  14. Informatix

    Informatix Expert Licensed User

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

    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) = ...

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

    AscySoft Active Member Licensed User

    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: Apr 30, 2013
  16. Informatix

    Informatix Expert Licensed User

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

    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.
  17. upsis

    upsis Member Licensed User

    file corrupted

    How do I know if the file is intact with CRC ok? Thanks.
  18. Informatix

    Informatix Expert Licensed User

    It's done automatically. If there's a mismatch, an exception is raised.

    You can know the CRC of a zipped file by using the ListZipEntries function.
  19. upsis

    upsis Member Licensed User


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

    Informatix Expert Licensed User

    If the program that zipped the archive has written a wrong CRC, you'll have troubles to unzip. Once written in the archive, this CRC cannot be altered or the archive itself is considered corrupted.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice