Topic: Bug in addstream?
Hi, firstly thanks a lot for this very handy mod
Now, when adding a stream that consists of a series of png files it doesn't seem to add it properly, almost like it doesn't recognise the compression of the png's., but I'm no expert on zip files... Any way I have created an example that illustrates the problem. It adds the stream twice to the zip file, once using addstream, and the other using addfile after saving the file to disk first. I can read the file back fine, but not the stream. and if you look into the zip file you can see that the stream is compressed to a much smaller size so something is wrong. Here's the code:
SuperStrict
Framework brl.basic
Import pub.zipengine
Import brl.pixmap
Import brl.pngloader
Local zip:ZipWriter = New ZipWriter
zip.OpenZip("test.zip", False)
'Create 10 pixmaps and save into a stream in the format:
'Int (size of png)
'Png file
'Int (size of png)
'Png file
'Int (size of png)
'Png file
'.. etc
Local iconbank:TBank = CreateBank()
Local tempstream:TStream = WriteStream(iconbank)
For Local c:Int = 1 To 10
Local pixmap:TPixmap = CreatePixmap(32, 32, PF_RGBA8888)
pixmap.WritePixel(c, c, $FFFFFFFF)
Local tempbank:TBank = CreateBank()
SavePixmapPNG(pixmap, tempbank)
tempstream.WriteInt(tempbank.Size())
WriteBank(tempbank, tempstream, 0, tempbank.Size())
Next
SaveBank(iconbank, "testfile")
'add the stream and file to the zip
zip.AddStream(tempstream, "teststream")
zip.AddFile("testfile")
zip.CloseZip()
'try and load them both back in again
Local ZipFile:ZipReader = New ZipReader
ZipFile.OpenZip("test.zip")
tempstream = ZipFile.ExtractFile("teststream")
DebugLog "Trying to load teststream"
For Local c:Int = 1 To 10
Local size:Int = tempstream.ReadInt()
If size
Local tempbank:TBank = CreateBank(size)
ReadBank(tempbank, tempstream, 0, size)
Local pixmap:TPixmap = LoadPixmapPNG(tempbank)
If pixmap
DebugLog "Pixmap loaded ok!"
Else
DebugLog "Failed to load pixmap!"
End If
Else
DebugLog "Failed to load pixmap!"
End If
Next
tempstream.Close
tempstream = ZipFile.ExtractFile("testfile")
DebugLog "Trying to load testfile"
For Local c:Int = 1 To 10
Local size:Int = tempstream.ReadInt()
If size
Local tempbank:TBank = CreateBank(size)
ReadBank(tempbank, tempstream, 0, size)
Local pixmap:TPixmap = LoadPixmapPNG(tempbank)
If pixmap
DebugLog "Pixmap loaded ok!"
Else
DebugLog "Failed to load pixmap!"
End If
Else
DebugLog "Failed to load pixmap!"
End If
Next
tempstream.Close
ZipFile.CloseZip()
End
Obviously my workaround is to simply save the file to disk first and then add that but it seems a little messy
Thanks!