B4J Library [b4j] zip/unzip

pd_ZipUnZip Library v2.1

B4X:
    dim zp as  PD_ZipUnzip
     zp.Initialize

   ' zip files/directories
    Dim File1 As String = File.Combine(File.DirApp,"1.txt")
    Dim File2 As String = File.Combine(File.DirApp,"2.txt")
    Dim folder1 As String = File.DirApp&"\testfolder"
 
    Dim targetFile As String = File.Combine(File.DirApp,"test1.zip")
 
    setOptions
 
    Dim success As Boolean = zp.Zip (Array(File1,File2,folder1),targetFile)
    Log("success : "&success)

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    zp.ZipAsync (Array(File1,File2),targetFile)
    Wait For ZipAsyncComplete (success As Boolean)
    If success Then
        Log("ZIP completed successfully")
    Else
        Log("ZIP operation failed")
    End If


B4X:
Sub setOptions
    'optional
    zp.CompressionLevel = 1
    zp.PasswordEnabled = True
    zp.Password = "12345"
End Sub

// Properties

void setPasswordEnabled(boolean value)
boolean getPasswordEnabled()
void setPassword(String value)
String getPassword()
void setCompressionLevel(int value)
int getCompressionLevel()

// ZIP Operations
boolean Zip(anywheresoftware.b4a.objects.collections.List items, String zipFile)
boolean Unzip(String zipFile, String destinationDirectory)
boolean Add(String zipFile, String source, String entryName)
boolean Remove(String zipFile, String entryName)


// Extraction Operations
boolean Extract(String zipFile, String entryName, String destinationDirectory)
boolean ExtractFiles(String zipFile, anywheresoftware.b4a.objects.collections.List entries, String destinationDirectory)


// Archive Information
anywheresoftware.b4a.objects.collections.List GetFiles(String zipFile)
anywheresoftware.b4a.objects.collections.List GetEntries(String zipFile)
int GetEntryCount(String zipFile)
long GetSize(String zipFile)

// Password Operations
boolean IsPasswordProtected(String zipFile)
boolean IsPasswordCorrect(String zipFile)


// Validation and Integrity
boolean IsValid(String zipFile)
boolean TestIntegrity(String zipFile)
 

Attachments

  • lib_v1.0.zip
    5.4 KB · Views: 50
  • lib_v2.0.rar
    198 KB · Views: 52
  • example.rar
    49.2 KB · Views: 55
  • lib_v2.1.rar
    199.6 KB · Views: 40
Last edited:

behnam_tr

Active Member
Licensed User
Longtime User
v2.1
added ZipAsync
bug fixed

B4X:
zp.ZipAsync(Array(File1,File2,File3,File4,File5),targetFile)
    Wait For ZipAsyncComplete (success As Boolean)
    If success Then
        Log("ZIP completed successfully")
    Else
        Log("ZIP operation failed")
    End If
 
Top