Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2009-02

zipper.pp TUnZipper: unzip to stream

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

theo

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 CRCCrc32Val then
            raise
EZipError.CreateFmt(SErrInvalidCRC,[Item.ArchiveFileName]);
        Finally
          Free;
        end;
  Finally
    CloseInput;
  end;
end;

Reply by email