Recent

Author Topic: Seeking a File in an archive created with ZlibAr  (Read 3423 times)

Hydexon

  • Full Member
  • ***
  • Posts: 170
Seeking a File in an archive created with ZlibAr
« on: February 26, 2011, 07:17:35 pm »
Hello!. I need a way to find an specific file inside of an archive created with ZlibAr and the component not has methods or functions for get an specific file without decompress all. How do this?
Lazarus 1.0.4 Stable - FPC 2.6.0 - gtk2 | Linux Mint 14 Nadia | GNOME Shell 3.6.2 - Awesome | Intel x86 | HP Mini 1020-LA Netbook (old)
Lazarus 2.0.2 Stable - FPC 3.0.2 - Windows | Lenovo IdeaPad Y

rajivsoft

  • New Member
  • *
  • Posts: 48
Re: Seeking a File in an archive created with ZlibAr
« Reply #1 on: April 05, 2011, 05:56:42 pm »
Hello!. I need a way to find an specific file inside of an archive created with ZlibAr and the component not has methods or functions for get an specific file without decompress all. How do this?
from example code the solution to your question must be something like this:
Code: Pascal  [Select][+][-]
  1. var
  2.   ArchStream: TMemoryStream;
  3.   FileStream: TMemoryStream;
  4.   ZReadArc: TZlibReadArchive;
  5.   X: Integer;
  6.   DestPath: String;
  7. begin
  8.   ArchStream := TMemoryStream.Create;
  9.   FileStream := TMemoryStream.Create;
  10.  
  11.   ArchStream.LoadFromFile(Edt_UnZip_src.Text);
  12.   ZReadArc := TZlibReadArchive.Create(ArchStream);
  13.   DestPath := Edt_UnZip_dst.Text;
  14.   ForceDirectory(DestPath);
  15.   for X := 0 to ZReadArc.Count - 1 do begin
  16. [b]    if (ReadArc.FilesInArchive[X].FileName = [color=maroon]file_name_you_need[/color]) then
  17.     begin [/b]
  18.       ZReadArc.ExtractFileToStream(X, FileStream);
  19.       FileStream.SaveToFile(TrimFilename(DestPath+'/'+ZReadArc.FilesInArchive[X].FilePath+'/'+ZReadArc.FilesInArchive[X].FileName));
  20.       FileStream.Position := 0;
  21.       FileStream.Size := 0;
  22. [b]    end;[/b]
  23.   end;
  24.   ZReadArc.Free;
  25.   ArchStream.Free;
  26.   FileStream.Free;
  27. end;

 

TinyPortal © 2005-2018