Table of Contents

28.1.2 Class Uncompress

For decompressing a file or unpacking a single file from an archive, the Type property and the Uncompress.File method are particularly informative, because before you can use a method of this class, you must select the compression driver you want to use for unpacking. There are two types to choose from: zlib or bzlib2.

The Uncompress.File method has the following syntax:

SUB File ( Source AS String, Target AS String )

Source: Path to the archive file.Target: Path to the unpacked file. If the unpacked file exists, it will be overwritten without prompting.

B1
Figure 28.1.2.1: Programme for unpacking an archive file according to two different algorithms

28.1.2.1 Project Un_Compress

The full source code for this project is also given and briefly explained in the comments below:

' Gambas class file
' To unpack a compressed file, you need the component gb.compress.
 
Private sFileSource As String
Private sFileTarget As String
 
Public Sub Form_Open()
  FMain.Center
  FMain.Resizable = False
End ' Form_Open()
 
Public Sub btnUnCompressZLIB_Click()
  Dim UCp As New Uncompress
 
  Dialog.Filter = ["*.gz", "Archive File", "*", "All Files"]
  Dialog.Path = User.Home
  Dialog.Title = "Select a file!"
  If Dialog.OpenFile() Then Return
 
  sFileSource = Dialog.Path
  sFileTarget = File.Dir(Dialog.Path) &/ File.BaseName(Dialog.Path)
 
  UCp.Type = "zlib"
  UCp.File(sFileSource, sFileTarget)
 
End ' UnCompressZLIB
 
Public Sub btnUnCompressBZLIB2_Click()
  Dim UCp As New Uncompress
 
  Dialog.Filter = ["*.bz2", "Archive file", "*", "All files"]
  Dialog.Path = User.Home
  Dialog.Title = "Select a file!"
  If Dialog.OpenFile() Then Return
 
  sFileSource = Dialog.Path
  sFileTarget = File.Dir(Dialog.Path) &/ File.BaseName(Dialog.Path)
 
  UCp.Type = "bzlib2"
  UCp.File(sFileSource, sFileTarget)
 
End ' UnCompressBZLIB2
 
Public Sub btnClose_Click()
  FMain.Close
End ' btnClose_Click()

28.1.2.1 Comment

Download

Project

Download