[fpc-devel] zipper.pp TUnZipper: unzip to stream

theo xpde at theo.ch
Wed Feb 11 11:44:58 CET 2009


Hi

It seems that TZipper / TUnZipper works great now.

But I was unable to find the following two functionalities:
1. Read the Zip directory without saving files to disk.
2. Unzip individual items to stream without saving to disk.

For my purpose I've extended TUnZipper with the two functions below.
It seems to work. Do you see any problems?
It would be nice if the FCL version had a similar "built-in" functionality.

Thank you
Theo

procedure TUnZipper.ReadZipDirectories;
begin
  Try
    OpenInput;
    ReadZipDirectory;
  Finally
    CloseInput;
  end;
end;

procedure TUnZipper.UnZipOneStream(Item: TZipFileEntry);
Var
  Count : Longint;
  CRC : LongWord;
  ZMethod : Word;
Begin
  Try
    OpenInput;
    ReadZipHeader(Item,CRC,ZMethod);
    if not assigned(item.Stream) then item.Stream:=TMemoryStream.create;
    if ZMethod=0 then
      begin
        Count:=item.Stream.CopyFrom(fZipFile,LocalHdr.Compressed_Size);
{$warning TODO: Implement CRC Check}
      end
    else
      With CreateDecompressor(Item, ZMethod, fZipFile, item.Stream) do
        Try
          OnProgress:=Self.OnProgress;
          OnPercent:=Self.OnPercent;
          DeCompress;
          if CRC<>Crc32Val then
            raise
EZipError.CreateFmt(SErrInvalidCRC,[Item.ArchiveFileName]);
        Finally
          Free;
        end;
  Finally
    CloseInput;
  end;
end;




More information about the fpc-devel mailing list