[delphizip] Re: Method ExtractStreamToStream

  • From: "Werner Kok" <werner@xxxxxxxxxxxxxxxxx>
  • To: <delphizip@xxxxxxxxxxxxx>
  • Date: Thu, 24 Feb 2005 09:55:06 +0200

Hi,

Thank you. I was under the impression that "STORED" means that the input
stream is compressed and needs to be decompressed. But maybe I
misunderstood. I am getting an access violation when I follow the help file
statement:

Flag := 8;
(pFlag( ZipMaster1.ZipStream.Memory ))^ := Flag;

Also I do not understand why this must be done on
ZipMaster1.ZipStream.Memory, as surely the input stream is the stream that
should contain the first 6 bytes and not the output stream?

I must be missing something terribly, sorry if I sound stupid.


Thanks for the help,
Werner


-----Original Message-----
From: delphizip-bounce@xxxxxxxxxxxxx
[mailto:delphizip-bounce@xxxxxxxxxxxxx]On Behalf Of Roger Aelbrecht
Sent: 23 February 2005 08:24 PM
To: delphizip@xxxxxxxxxxxxx
Subject: [delphizip] Re: Method ExtractStreamToStream


Werner Kok wrote:
> Hi,
>
> Please look at what I'm doing below and help my frustrated soul, I
> will be forever gratefull!
>
>
> procedure TForm1.Button1Click(Sender: TObject);
> var FileData: TMemoryStream;
>     MyData: TMemoryStream;
>     MyOutData: TZipStream;
>     Buf1: Array[1..6] of Byte;
>
> begin
>
> FileData := TMemoryStream.Create;
> FileData.Position := 0;
> FileData.LoadFromFile('c:\Example.zip');
>
> MyData := TMemoryStream.Create;
> MyData.Position := 0;
> Buf1[1] := 0;
> Buf1[2] := 0;
> Buf1[3] := 9;
> Buf1[4] := 9;
> Buf1[5] := 9;
> Buf1[6] := 9;
> MyData.Write(Buf1,6);
> MyData.Position := 6;
> MyData.CopyFrom(FileData,0);
> MyData.Position := 0;
>
> MyOutData := ZipMaster1.ExtractStreamToStream(MyData, 32768);
> MyOutData.Position := 0;
> MyOutData.SaveToFile('c:\Extracted.txt');
>
> end;
>
>
>
> Why oh why is the file 'c:\Extracted.txt' still the compressed zip
> file?
>
>
>
>
> Thank you so much!,
>
> Werner Kok
>
>


As far as I can see in your code the extra bytes you entered are not
correct.
You have set it as 'stored' so no decompression is done, because the UnzDLL
thinks the data in the stream was not compressed.

>From the help file :
<quote>

The first 6 bytes of the input stream are reserved:

- The first two bytes are used as a flag, STORED = 0 or DEFLATED = 8.

Type
 pFlag = ^Smallint;
 pCRC = ^Cardinal;
Var
 Flag: SmallInt;
 CRC: Cardinal;

Flag := 8;
 (pFlag( ZipMaster1.ZipStream.Memory ))^ := Flag;

</quote>

So for a compressed file the flag should be set to 8.

Then there is the problem of the CRC.
the last 4 bytes are the calculated CRC, if you do not have this
value you will receive CRC errors, of course you can ignore them.
To ignore the CRC errors create an OnCRCError event handler
and set the DoExtract parameter to true.

HTH

--
Roger Aelbrecht
http://home.tiscali.be/driehoeksw



--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 266.4.0 - Release Date: 22/02/2005

-----------
To unsubscribe from this list, send an empty e-mail
message to:
  delphizip-request@xxxxxxxxxxxxx
and put the word unsubscribe in the subject.

-----------
To unsubscribe from this list, send an empty e-mail 
message to:
  delphizip-request@xxxxxxxxxxxxx 
and put the word unsubscribe in the subject.

Other related posts: