Has anyone used MBS compression plugin already for Web2.0? Is it possible to compress multiple in memory webfiles? I have an app which is generating a lot of files (20-30) (all very small). So I think it would be best to put them all in a zip file and force download the zip only. Should most likely be zip, so that it will work on all platforms.
All coding I find so far seems to compress files that were created on disc and not in memory …
I use MBS to Zip both files and folders (one Method). I also use the MBS Encryption classes to Zip encrypt a String or MemoryBlock (across Desktop, Web and Mobile) before transferring to a REST WebApp. This is all for Web 2.0 too.
Thank you all for your help. ArchiveWriterMBS is great and it is pretty straight forward. Here my code, in case someone else might find it useful one day:
// Array to store the created files
var files() as WebFile
// >> created as properties in the IDE (e.g. file1 as webfile)
file1 = new WebFile
file2 = new WebFile
file3 = new WebFile
zippedFile = new Webfile
// << created as properties in the IDE (e.g. file1 as webfile)
// Populating the webfiles and adding them to an array
file1.MimeType = "text/plain"
file1.ForceDownload = False
file1.Filename = "file1.txt"
file1.Data = "Lore Lipsum 1"
files.add(file1)
file2.MimeType = "text/plain"
file2.ForceDownload = False
file2.Filename = "file2.txt"
file2.Data = "Lore Lipsum 2"
files.add(file2)
file3.MimeType = "text/plain"
file3.ForceDownload = False
file3.Filename = "file3.txt"
file3.Data = "Lore Lipsum 3"
files.add(file3)
// Defining the ZIP File
zippedFile.MimeType = "application/zip"
zippedFile.ForceDownload = true
zippedFile.Filename = "myCompressedFiles.zip"
// defining the zip file in memory
Var myZip as new ArchiveWriterMBS
myZip.SetFormatZip
myZip.ZipSetCompressionDeflate
var check as boolean = myZip.CreateMemoryFile
if check then
// Looping over all the files in my array of files
for each file as webfile in files
// creating an entry in the zip file per webfile in the array
var e as new ArchiveEntryMBS
e.PathName = file.Filename
e.Size = lenb( file.Data )
e.Permissions = &o0644
e.FileType = e.kFileTypeRegular
myzip.WriteHeader e
call myZip.WriteData file.Data
myZip.FinishEntry
next
myZip.Close
end if
// copy the Zip-File from the memory into the in-memory ZIP-WebFile
zippedFile.data = myZip.MemoryData
// download the zip File
gotoUrl( zippedFile.url )
@David_Cox@Christian_Schmitz can you help me on this one, please? Things are getting a bit more complex, so I want to group my files in different folders within the zip file.
I achieved to create a folder in my zip:
Var myZip as new ArchiveWriterMBS
Var e as new ArchiveEntryMBS
e.pathname = "myFolderName"
e.FileType = e.kFileTypeDirectory
e.Permissions = &o0755
myzip.WriteHeader e
myZip.FinishEntry
But I don’t know how to address this newly created folder within the zip file.
doesn’t work, so how can I either “move” into the newly created folder or address it correctly. Must be something simple, but I don’t see how to do it and don’t see anything in the examples either. Or is this not possible at all, but then I’m surprised that I succeeded in creating a folder ;-).
I’m obviously not normal … I tried everything! Magic keyword to the solution: “foreslash”! Don’t ask me why I only tried backslash … and don’t ask me why I even tried backslash … 2h of lifetime gone with the wind and for the birds!
It’s always bad for your own ego to ask Christian a question :-), I’m still laughing and can’t work any more.
If you guys would know what I tried today to get this working … and then Christian tells you: well, just add your desired foldername to the pathname :-).