User Tools

Site Tools


k28:k28.1:k28.1.2:start

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

  • First, an Uncompress object is created.
  • Then you can select the archive file in the dialogue. The file filter is set to gz archives and bz2 archives in the project. These settings follow the recommendations in connection with the 2 algorithms used. The unpacked file is saved here in the same directory as the archive file.
  • Finally, the selected archive file is unpacked according to the selected algorithm (type) using the paths for the source and target files.

Download

Project

Download

The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k28/k28.1/k28.1.2/start.txt · Last modified: 30.01.2022 (external edit)

Page Tools