Platforms to show: All Mac Windows Linux Cross-Platform

/Compression/Archive/CreateArchive iOS


Required plugins for this example: MBS Compression Plugin, MBS Main Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Compression/Archive/CreateArchive iOS

This example is the version from Wed, 9th Feb 2021.

Project "CreateArchive iOS.xojo_binary_project"
Class App Inherits MobileApplication
End Class
Class MainScreen Inherits MobileScreen
Control Output Inherits MobileTextArea
ControlInstance Output Inherits MobileTextArea
Constraint Constraint 1
Constraint Constraint 2
Constraint Constraint 3
Constraint Constraint 4
End Control
EventHandler Sub Opening() CreateTestFiles CreateArchive SpecialFolder.Documents.Child("test"), SpecialFolder.Documents.child("test.tar"), ArchiveWriterMBS.kFilterNone, ArchiveWriterMBS.kFormatTar log "done" log SpecialFolder.Documents.child("test.tar").NativePath End EventHandler
Sub CreateArchive(item as FolderItem, destFile as FolderItem, Filter as integer, Format as integer, ZipLevel as integer = 0) dim flags as integer = 0 flags = Bitwise.BitOr(flags, ArchiveReaderMBS.kExtractTime) flags = Bitwise.BitOr(flags, ArchiveReaderMBS.kExtractPermission) flags = Bitwise.BitOr(flags, ArchiveReaderMBS.kExtractACL) flags = Bitwise.BitOr(flags, ArchiveReaderMBS.kExtractFileFlags) dim aw as new ArchiveWriterMBS aw.AddFilter filter if aw.Lasterror <> aw.kArchiveOK then log "Failed to set filter with error "+aw.Lasterror.ToString+": "+aw.ErrorString exit end if aw.SetFormat Format if aw.Lasterror <> aw.kArchiveOK then log "Failed to set format with error "+aw.Lasterror.ToString+": "+aw.ErrorString exit end if Select case ZipLevel case 1 aw.ZipSetCompressionStore case 2 aw.ZipSetCompressionDeflate end Select log "Create "+destFile.name if not aw.CreateFile(destFile) then log "Failed to create file: "+aw.ErrorString return end if if not aw.SetCurrentWorkingDirectory(item.parent) then log "Failed to set working directory." return end if dim disk as new ArchiveReadDiskMBS if not disk.Open(item.name) then log "Failed to set item for compress." return end if do dim entry as ArchiveEntryMBS = disk.NextHeader if disk.Lasterror = disk.kArchiveEOF then exit end if if disk.Lasterror <> disk.kArchiveOK then log "Failed to get next item with error "+(disk.Lasterror.ToString)+": "+disk.ErrorString exit end if if entry = nil then break exit end if dim PathName as string = entry.PathName dim FileName as string = PathName.NthField("/", PathName.CountFields("/")) If FileName.Left(1) = "." Then Continue // skip disk.Descend log "add "+PathName // make flat archive 'entry.PathName = filename aw.WriteHeader entry if aw.Lasterror <> aw.kArchiveOK then log "Failed to write header with error "+aw.Lasterror.ToString+": "+aw.ErrorString exit end if dim size as int64 = aw.WriteData(disk) log size.ToString + " bytes" // optional close each item. 'aw.FinishEntry if aw.Lasterror <> aw.kArchiveOK then log "Failed to finish entry with error "+aw.Lasterror.ToString+": "+disk.ErrorString exit end if loop aw.Close disk.Close End Sub
Sub CreateTestFiles() Dim f As FolderItem = SpecialFolder.Documents.Child("test") f.CreateFolder // write test file dim t as TextOutputStream = TextOutputStream.Create(f.Child("test.txt")) t.WriteLine "Hello World" // write two files with logos dim p as Picture = LogoMBS(500) p.Save(f.Child("mbs.jpg"), picture.Formats.JPEG) p.Save(f.Child("logo.jpg"), picture.Formats.JPEG) // write second text file t = TextOutputStream.Create(f.Child("other.txt")) t.WriteLine "Just a test" // write 10 MB file with all zeros, good to compress dim b as BinaryStream = BinaryStream.Create(f.Child("zeros.txt"), true) dim m as new MemoryBlock(1024*1024*10) b.Write m dim subfolder as FolderItem = f.Child("sub folder") subfolder.CreateFolder p.Save(subfolder.Child("logo2.jpg"), picture.Formats.JPEG) End Sub
Sub log(s as string) output.Text = output.Text + s + EndOfLine End Sub
End Class
Class LaunchScreen Inherits iosView
End Class
End Project

The items on this page are in the following plugins: MBS Compression Plugin.


The biggest plugin in space...