Platforms to show: All Mac Windows Linux Cross-Platform
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
This example is the version from Thu, 12th Dec 2018.
Project "untar.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Open()
dim f as FolderItem = GetFolderItem("test.zip")
if not f.Exists then
break
log "No test.zip?"
return
end if
call ArchiverMBS.SetCurrentWorkingDirectory(f.parent)
dim ar as new ArchiveReaderMBS
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
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
aw.WriteHeader entry
if aw.Lasterror <> aw.kArchiveOK then
log "Failed to read write header with error "+str(aw.Lasterror)+": "+aw.ErrorString
return
end if
dim BytesWritten as Int64 = aw.WriteData(ar)
log str(BytesWritten)+" bytes written."
if aw.Lasterror <> aw.kArchiveOK then
log "Failed to read write data with error "+str(aw.Lasterror)+": "+aw.ErrorString
'return
end if
aw.FinishEntry
if aw.Lasterror <> aw.kArchiveOK then
log "Failed to close file with error "+str(aw.Lasterror)+": "+aw.ErrorString
return
end if
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)
LogWindow.list.addrow s
End Sub
End Module
End Project
See also:
The items on this page are in the following plugins: MBS Compression Plugin.