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/GZip/GZip
This example is the version from Sun, 17th Mar 2012.
Project "GZip.xojo_binary_project"
FileTypes
Filetype application/binary
End FileTypes
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
EventHandler Sub Open()
dim s,d,e as FolderItem
MsgBox "Please change the file paths!"
s=SpecialFolder.Desktop.Child("MacExpo.pdf")
d=SpecialFolder.Desktop.Child("test.gz")
e=SpecialFolder.Desktop.Child("MacExpo2.pdf")
if CompressFile(s,d) then
MsgBox "ok"
else
MsgBox "failed"
end if
if Decompressfile(d,e,"application/binary") then
MsgBox "ok"
else
MsgBox "failed"
end if
quit
End EventHandler
Function CompressFile(source as folderitem, dest as folderitem) As boolean
dim z as GZipFileMBS
dim f as FolderItem
dim b as BinaryStream
z=new GZipFileMBS
b=source.OpenAsBinaryFile(false)
if b<>nil then
if z.Open(dest,"wb") then
while not b.eof
z.Write b.Read(1000000)
if z.Lasterror<>0 then
Return false
end if
wend
z.Close
if z.Lasterror=0 then
Return true
end if
end if
end if
End Function
Function DeCompressFile(source as folderitem, dest as folderitem, type as string) As boolean
dim z as GZipFileMBS
dim f as FolderItem
dim b as BinaryStream
z=new GZipFileMBS
b=dest.CreateBinaryFile(type)
if b<>nil then
if z.Open(source,"rb") then
while not z.eof
b.Write z.Read(1000000)
if z.Lasterror<>0 then
Return false
end if
wend
z.Close
if z.Lasterror=0 then
Return true
end if
end if
end if
End Function
End Class
End Project
See also:
The items on this page are in the following plugins: MBS Compression Plugin.