Zip/Unzip Library

alwaysbusy

Expert
Licensed User
This is a library to zip and unzip files and folders.

Functions:

ABZipDirectory(sourceDir, zipFile)

zip a folder with all its files and subdirectories

Example:

B4X:
myzip.ABZipDirectory(sdRoot & "start", sdRoot & "myZip.zip")
ABZipfile(sourcePath, sourceFile, zipFile)

Zip a single file
sourcePath must end with "/"

Example:

B4X:
myzip.ABZipFile(sdRoot & "start/" , "test4.txt", sdRoot & "myZipOneFile.zip")
ABUnzip(zipFile, targetPath)

Unzip a zip file

Example:

B4X:
myZip.ABUnzip(sdRoot & "myZip.zip", sdRoot & "target")
ABListZip(zipFile)

List the contents of a zip file

Example:

B4X:
Dim myZipFile as ABZipContent 

listview1.Clear
counter = myzip.ABListZip(sdRoot & "myZipOneFile.zip")
For a = 0 To counter - 1
   myZipFile = myZip.ABGetListItem(a)
   listview1.AddTwoLines(myZipfile.Name, "Size: " & MyZipfile.Size & " bytes   Compressed Size: " & myzipFile.CompressedSize & " bytes")
Next
ABGetListItem(int index)

Get one if the items in the zipfile to get more information. Fill this list first by calling ABListZip()

Example: see ABListZip()
 

Attachments

kickaha

Well-Known Member
Licensed User
Is it possible to add support for zip files that are in the assets directory?

I have a lot of files in the assets directory that need to be on the SD card for updating. I zipped them up and added the zip to the assets, but I cannot unzip it directly. As a work-round I copy it to the zip to the internal cache and unzip from there.
 

kickaha

Well-Known Member
Licensed User
Thanks Erel, I know I can do that but using a zip file simplifies the coding. The reasons for using a zip file are:

1) Unzipping it recreates the directory structure
2) I do not need a load of "File.Copy" commands
3) I can add files to the zip later on without altering the code

Copying to the internal cache before unzipping is not a problem at all, but I was wondering if it is possible to do an unzip directly from the assets.

Edit to add:

While I remember, the code in the first post confused me slightly:
myZip.ABUnzip(sdRoot & "myZip.zip", sdRoot & "target")
I did not at first appreciate that sdRoot had already had the trailing "/" added to it so I was trying to use
myZip.ABUnzip(File.DirAssets & "myZip.zip", File.DirInternal & "target")
Instead of
myZip.ABUnzip(File.DirAssets & "/myZip.zip", File.DirInternal & "/target")
 
Last edited:

Cor

Active Member
Licensed User
extract just 1 file from the zip

will it be possible to extract just 1 file from the zip?
 

schimanski

Well-Known Member
Licensed User
Unzip only a few files from a zip-file

Im very interessted in the last question from Cor. I have tried something, but it doesn't work. Is there a way to unzip only one or a few files out of the whole zip-File? It will be useful by working with many tiles of maps....

Thanks for an answer....
 

Amalkotey

Active Member
Licensed User
@alwaysbusy:

I have sent you a PM via the forum. Did you get this? Please read. It would be nice if you could help me!

regards
Amalkotey
 

icakinser

Member
Licensed User
what about in memory compression? For example, compressing/decompressing a string value instead of a file? Developed my own ebook format using json and compressed sections instead of a container zip. Would love to be able to port it to Android.
 

Djembefola

Active Member
Licensed User
ABUnzip is stripping Characters in Filenames

I have downloaded a zipfile, that contains a folder with 3 files.

Name of the zipfile "olé.zip"
Name of the zipped folder: "/olé"
Name of the files in "/olé":

"olé 090.mp3"
"olé 100.mp3"
"olé 110.mp3"

Downloading the zip-file and unzipping it with ABUnzip to the Destination Folder works fine, the unzipped folder has the correct name, but the three files in the folder are renamed to

"ol 090.mp3"
"ol 100.mp3"
"ol 110.mp3"

Is this a Bug in the ABUnzip Function or did i do something wrong, when i uploaded the zipfile with Filezilla.

Regards,
Joerg
 
Top