Platforms to show: All Mac Windows Linux Cross-Platform
/Compression/Old ZipMBS class/unzip with folders and encryption
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/Old ZipMBS class/unzip with folders and encryption
This example is the version from Sat, 27th Nov 2020.
Project "unzip with folders and encryption.xojo_binary_project"
FileTypes
Filetype text
End FileTypes
Class Window1 Inherits Window
Control EditField1 Inherits TextArea
ControlInstance EditField1 Inherits TextArea
End Control
EventHandler Sub Open()
Const password = "Hello"
Dim f As FolderItem
dim z as UnZipMBS
dim lines(-1) as string
dim s as string
dim info as UnZipFileInfoMBS
f=SpecialFolder.Desktop.Child("test.zip")
if f=nil or f.Exists=False then
MsgBox "You need a test.zip file on your desktop folder."
Return
end if
z=new UnZipMBS(f)
dim destfolder as FolderItem = f.Parent.Child("test.zip folder")
lines.Append "FileCount: "+str(z.Count)
z.GoToFirstFile
do
dim isFolder as Boolean=false
dim path as string = z.FileName
// we need to know text encoding, so we guess ASCII here
path = DefineEncoding(path, encodings.ASCII)
lines.Append "CurrentFileName: "+path
if Right(path,1)="/" then
isFOlder=true
end if
if encodings.UTF8.IsValidData(path) then
path = DefineEncoding(path, encodings.UTF8)
end if
f=getpath(destfolder, path)
info=z.FileInfo
lines.Append "uncompressedSize: "+str(info.uncompressedSize)
lines.Append "compressedSize: "+str(info.compressedSize)
lines.Append "date: "+info.date.ShortDate+" "+info.date.ShortTime
if isfolder then
f.CreateAsFolder
else
dim b as BinaryStream=f.CreateBinaryFile("")
if b<>nil then
z.OpenCurrentFile(password)
if z.Lasterror=0 then
do
s=z.ReadCurrentFile(100000)
b.Write s
If z.Lasterror = 0 Then
// okay
Elseif z.Lasterror = -3 Then
lines.Append "Failed to read file! Password wrong?"
Break
Else
lines.Append "Failed to read file!"
Break
End If
loop until lenb(s) = 0
z.CloseCurrentFile
b.Close
end if
Else
lines.Append "Failed to create binary stream for "+f.NativePath
end if
end if
f.ModificationDate=info.Date
#if not TargetLinux then
f.CreationDate=info.date
#endif
z.GoToNextFile
loop until z.Lasterror<>0
EditField1.text=Join(lines,EndOfLine)
End EventHandler
Function getpath(parent as FolderItem, path as string) As FolderItem
dim i,c as integer
c=CountFields(path,"/")
dim f as FolderItem = parent
for i=1 to c
dim s as string = NthField(path,"/",i)
if s<>"" then
if f.Exists=False then
f.CreateAsFolder
end if
f=f.Child(s)
end if
next
Return f
End Function
Protected Function str(b as boolean) As string
if b then
Return "true"
else
Return "false"
end if
End Function
End Class
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu5 = ""
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "Clear"
MenuItem UntitledMenu4 = ""
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = ""
End MenuBar
Class App Inherits Application
End Class
End Project
See also:
- /Compression/Old ZipMBS class/CompressFiles test
- /Compression/Old ZipMBS class/create epub file
- /Compression/Old ZipMBS class/ExtractFiles test
- /Compression/Old ZipMBS class/unzip
- /Compression/Old ZipMBS class/unzip with folders
- /Compression/Old ZipMBS class/unzip with memory
- /Compression/Old ZipMBS class/unzip with string
- /Compression/Old ZipMBS class/zip
- /Compression/Old ZipMBS class/zip append
- /Compression/Old ZipMBS class/zip images
The items on this page are in the following plugins: MBS Compression Plugin.