Platforms to show: All Mac Windows Linux Cross-Platform

/Compression/Archive/Write zip Archive


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

Last modified Tue, 21th Apr 2025.

You find this example project in your MBS Xojo Plugin download as a Xojo project file within the examples folder: /Compression/Archive/Write zip Archive

Download this example: Write zip Archive.zip

Project "Write zip Archive.xojo_binary_project"
Class App Inherits ConsoleApplication
EventHandler Function Run(args() as String) As Integer Dim a As New ArchiveWriterMBS a.SetFormatZip a.ZipSetCompressionDeflate dim f as FolderItem = SpecialFolder.Desktop.Child("test.zip") if not a.CreateFile(f) then break // failed else dim data as string = "Hello World test file. Hello World again." dim e as new ArchiveEntryMBS e.PathName = "Hello World.txt" 'e.Size = lenb(data) e.Permissions = &o0644 e.FileType = e.kFileTypeRegular a.WriteHeader e call a.WriteData data a.FinishEntry test a a.Close end if End EventHandler
Sub logError(n as string, s as string) Print n + " "+ s End Sub
Sub logNote(n as string, s as string) Print n + " "+ s End Sub
Sub test(archive as ArchiveWriterMBS) Dim item As FolderItem = SpecialFolder.Desktop.Child("Installation.pdf") Dim entry As ArchiveEntryMBS entry = New ArchiveEntryMBS entry.PathName = item.Name 'entry.Size = item.Length entry.Permissions = &o0644 entry.FileType = entry.kFileTypeRegular entry.CTime = item.CreationDateMBS entry.MTime = item.ModificationDateMBS Try Dim binaryStream As BinaryStream binaryStream = BinaryStream.Open(item, False) If binaryStream = Nil Then logError CurrentMethodName, "binaryStream is nil" Else logNote CurrentMethodName, "opened " + item.NativePath Dim data As MemoryBlock data = binaryStream.Read(binaryStream.Length) binaryStream.Close() logNote CurrentMethodName, "closed " + item.NativePath archive.WriteHeader(entry) Dim bytesWritten As Int64 bytesWritten = archive.WriteData(data) If bytesWritten <> item.Length Then logError CurrentMethodName, "not all data was written" End If archive.FinishEntry() End If Catch e As RuntimeException logError CurrentMethodName, "throws " + e.Message End Try End Sub
End Class
Sign
End Sign
End Project

See also:

Download this example: Write zip Archive.zip

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


The biggest plugin in space...