ZipFile - GetFileStream versus JPEG.LoadFromStream error lazarus / 5-Lazarus Extra Components ---------------------------------------------------------------------- elioenaishalom · 2013-11-20 15:05 Hi, if anyone can help me I thank in advance, because I could not solve yet ... case it is using images recorded in the zip file and then retrieve them as needed. function TDataModule1.ZipExtract(FileName: string): boolean; var   MyZipFile: TZipFile;   P: string;   J: TJPEGImage;   buflen: longword;   lStream: TMemoryStream; begin   Result := False;   P := ExtractFilePath(Application.ExeName) + 'ZipRes.zip';   if not FileExists(P) then     exit;   J := TJPEGImage.Create;   lStream := TMemoryStream.Create;   MyZipFile := TZipFile.Create(DataModule1);   try     MyZipFile.FileName := P;     MyZipFile.Activate;     lStream := MyZipFile.GetFileStream(FileName, buflen);     SetLength(P, buflen);     lStream.ReadBuffer(P[1], buflen);     lStream.Position := 0;     J.LoadFromStream(lStream); { JPEG error here }       J.SaveToFile(ExtractFilePath(Application.ExeName) + FileName);     Result := true;   finally     lStream.Free;     J.Free;     MyZipFile.Free;   end; end; ---------------------------------------------------------------------- marcov · 2013-11-20 21:44 My guess would be putting the position line before the readbuffer? ---------------------------------------------------------------------- elioenaishalom · 2013-11-20 22:53 Quote from: marcov on November 20, 2013, 10:44:07 pmMy guess would be putting the position line before the readbuffer? thank you for your attention - worked partially (not JPEG error), but the size of the saved file is null. I noticed that the size of lStream := MyZipFile.GetFileStream(FileName, buflen); (lStream.size) is the same as the packed file; well, the question is - how to GetFileStream from unpacked file ? ---------------------------------------------------------------------- engkin · 2013-11-20 23:20 "My guess would be putting the position line before" and after "the readbuffer?" ---------------------------------------------------------------------- elioenaishalom · 2013-11-21 01:33 Quote from: engkin on November 21, 2013, 12:20:58 am"My guess would be putting the position line before" and after "the readbuffer?" OK, I put - JPEG error again     lStream.Position := 0;     lStream.ReadBuffer(P[1], buflen);     lStream.Position := 0;     J.LoadFromStream(lStream); { JPEG error here } ---------------------------------------------------------------------- engkin · 2013-11-21 02:24 Your problem is with TZipFile, find an alternative. According to the wiki: QuoteFile compression is currently not implemented ... Currently only uncompressed files can be read and written to and from a zipfile. That's why: Quote... the size of ... (lStream.size) is the same as the packed file; Anyway maybe you want to ask your TJPEGImage if it supports the stream you are providing. Try: Code: [Select]..   lStream.Position := 0;   if J.IsStreamFormatSupported(lStream) then     J.LoadFromStream(lStream, buflen)   else     //Whatever you want to do if it does not support your stream!! It simply checks the first two bytes of your steam. ---------------------------------------------------------------------- elioenaishalom · 2013-11-21 04:07 ok,  thanks I'll try pasZlib