Platforms to show: All Mac Windows Linux Cross-Platform
/Compression/Archive/untar with extract
Required plugins for this example: MBS Compression Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Compression/Archive/untar with extract
This example is the version from Sat, 10th May 2019.
Project "untar with extract.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Open()
Dim f As FolderItem = SpecialFolder.Desktop.child("test.zip")
if not f.Exists then
break
log "No test.zip?"
return
end if
Call ArchiverMBS.SetCurrentWorkingDirectory(f.parent)
dim ar as new MyArchiveReaderMBS
dim aw as new ArchiveWriteDiskMBS
aw.SetStandardLookup // lookup UIDs and GIDs
dim flags as integer = ar.kExtractTime
// handle permissions
flags = BitwiseOr(flags, ar.kExtractPermission)
flags = BitwiseOr(flags, ar.kExtractFileFlags)
flags = BitwiseOr(flags, ar.kExtractACL)
// support Mac Metadata
flags = BitwiseOr(flags, ar.kExtractMacMetadata)
// a few flags to avoid trouble
flags = BitwiseOr(flags, ar.kExtractSecureNoAbsolutePath)
flags = BitwiseOr(flags, ar.kExtractSecureNoDotDot)
// enable overwrite
flags = BitwiseOr(flags, ar.kExtractUnlink)
aw.Options = flags
// any file format including tar, zip and 7zip
ar.SupportFormatAll
ar.SupportFilterAll
Log "Open "+f.name
if not ar.OpenFile(f) then
log "Failed to open file with error "+str(ar.Lasterror)+": "+ar.ErrorString
return
end if
// store for progress event
ar.TotalSize = f.Length
Do
dim entry as ArchiveEntryMBS = ar.NextHeader
If ar.Lasterror = ar.kArchiveEOF Then Exit
If ar.Lasterror <> ar.kArchiveOK Then
Log "Failed to read file header with error "+Str(ar.Lasterror)+": "+ar.ErrorString
Return
End If
Log "Extract "+entry.PathName
ar.extract(entry, aw)
loop
ar.Close
aw.Close
log "done"
End EventHandler
End Class
Class LogWindow Inherits Window
Control List Inherits Listbox
ControlInstance List Inherits Listbox
End Control
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Module LogModule
Sub log(s as string)
System.DebugLog s
LogWindow.list.addrow s
End Sub
End Module
Class MyArchiveReaderMBS Inherits ArchiveReaderMBS
EventHandler Sub ExtractProgress(entry as ArchiveEntryMBS)
Log Str(Me.PositionCompressed)+" bytes of "+_
Str(Me.TotalSize)+" bytes: "+_
Str(Me.PositionCompressed / Me.TotalSize, "0%")
End EventHandler
Property TotalSize As Int64
End Class
End Project
See also:
The items on this page are in the following plugins: MBS Compression Plugin.