Forum > Packages and Libraries

zipper.pas empty zipped up memorystream ?

(1/1)

Mike J:
I was trying to zip up Tmemorystreams, instead of saving the contents out as temp files then zipping the contents up, the resulting zip (on inspection), shows the file added with the correct size in bytes being reported, but extracts as *empty* (zero bytes) ?

Code fragment


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---zipFile.Filename:='test.zip';tmpMemFile:=mimetypeWrite();zfe:=zipFile.Entries.AddFileEntry(tmpMemFile, 'mimetype');zipFile.ZipAllFiles;                                       

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function TePub.mimetypeWrite():TMemoryStream;  var    meta: TStringList;    memFile: TMemoryStream;  begin    memFile:=TMemoryStream.Create;    meta := TStringList.Create;    meta.Add('application/epub+zip');    meta.SaveToStream(memFile);    meta.Free;    Result:=memFile;  end;             

Laksen:
Remember to do a memFile.Seek(0, soFromBeginning); after writing to it. Otherwise you'll be reading from the end of the memory stream

Mike J:
Nothing there to remember, didn't know that.

Guess the question is... why wouldn't the zip class do that automatically?

Laksen:
It's just writing some bunch to a stream, so should it rewind to the start of the memory stream or to where it started to write?

It's a well known paradigm, where you can then very easily store something after other things. And mostly this is an "issue" with memory streams, so people most often just have to learn the hard way :)

Mike J:

--- Quote from: Laksen on December 17, 2011, 02:21:15 am ---It's just writing some bunch to a stream, so should it rewind to the start of the memory stream or to where it started to write?

It's a well known paradigm, where you can then very easily store something after other things. And mostly this is an "issue" with memory streams, so people most often just have to learn the hard way :)

--- End quote ---

hrmmm, something to keep in mind for sure.

ᏩᏙ for your helping me

Navigation

[0] Message Index

Go to full version