I must be missing something simple - as usual. Using ArchiveWriterMBS the zip file is created fine and can be unzipped. But the length of the files is 0 bytes. As far as I can see there is no error.
dim files(-1) as FolderItem
files.Add(SpecialFolder.Desktop.Child("Screenshot 2024-08-02 at 14.55.36 copy.png"))
files.Add(SpecialFolder.Desktop.Child("Screenshot 2024-08-02 at 14.55.36.png"))
dim zipFilename as FolderItem = SpecialFolder.Desktop.Child("test.zip")
// Create a new ArchiveWriterMBS object
Dim zip As New ArchiveWriterMBS
zip.SetFormatZip
zip.ZipSetCompressionDeflate
// Create the zip file
If Not zip.CreateFile(zipFileName) Then
'MsgBox("Failed to create zip file: " + zip.LastErrorMessage)
Return
End If
// Add files to the zip archive
For Each file As FolderItem In files
If not file.Exists Then continue
// Read the file data
Var binStream As BinaryStream = BinaryStream.Open(file, False)
Var fileData As String = binStream.Read(binStream.Length)
binStream.Close
'add an archive entry
dim entry as new ArchiveEntryMBS
entry.PathName = file.Name
entry.Size = binStream.Length
entry.Permissions = &o0644
entry.FileType = entry.kFileTypeRegular
zip.WriteHeader(entry)
dim theResult as Integer = zip.WriteData(fileData)
beep
zip.FinishEntry
next
// Close the zip file
zip.Close
What am I doing wrong?
4 posts - 4 participants