Sign in Join
Wiki copytemporary

unzip

Unzip and zip

The unzip and zip package contains several routines to unzip or zip files on every Lazarus supported platforms. There are 4 units:

The zip library unit is included in Lazarus 2.

Example

Zip compression is in widespread use. It is also used to compress EPUB files.

pascal
uses
  unzip,ziputils;
const  cover  =  'cover.jpeg';
var UnZipper          : unzFile;
    epubfile, UnPackPathFile : String;
    zfinfos  :  unz_file_info_ptr;
    i        :  Integer;
    li_SizeRead,li_SizeWrite,li_TotalW  : Longint;
    lb_FoundFile : Boolean;
    FBuffer  :  TExtFileBuffer;
    li_HandleDest : Integer;    
begin
   epubfile :='/Your/Path/to/epub';
   UnPackPathFile :='/Your/Path/to/uncompressed/file';
   try
     UnZipper:=unzOpen(@epubfile[1]);
     if unzLocateFile(UnZipper,@cover[1],2)= UNZ_OK then
       try
         unzOpenCurrentFile(UnZipper);
         Getmem(zfinfos,SizeOf(zfinfos));
         unzGetCurrentFileInfo(UnZipper,zfinfos,@cover[1],SizeOf(cover),nil,0,nil,0);
         lb_FoundFile := False;
         if not FileExistsUTF8(UnPackPathFile)
           Then  FileCreateUTF8(UnPackPathFile);
         li_HandleDest := FileOpenUTF8(UnPackPathFile, fmopenwrite );
         while not lb_FoundFile do
           begin
             li_SizeRead := unzReadCurrentFile(UnZipper,@FBuffer[0],high ( Fbuffer ) + 1);
             if li_SizeRead < high ( Fbuffer ) + 1 then lb_FoundFile := True;
             li_SizeWrite := Filewrite(li_HandleDest,Fbuffer,li_SizeRead);
             inc( li_TotalW, li_SizeWrite );
           end;
         Break;
       finally
         Freemem(zfinfos,SizeOf(zfinfos));
     end;
   finally
     try
       FileClose(li_HandleDest);
     finally
       unzCloseCurrentFile(UnZipper);
       unzClose(UnZipper);
     end;
   end;   
end.

See also

Go back to Packages List


From the Free Pascal wiki, page "unzip", as it stood on 2020-08-02 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 1, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.