Sign in Join
Wiki copytemporary

unzip: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: unzip

OldNewLine
1+## Unzip and zip
2+
3+The unzip and zip package contains several routines to unzip or zip files on every Lazarus supported platforms. There are 4 units:
4+
5+- **zip** a unit which implements an zip mechanism with native Pascal links.
6+- **unzip** a unit which implements an unzip mechanism with native Pascal links.
7+- **ziputils** contains some tools for the unzip unit.
8+- **zipbase** a unit which defines the interface for the info-zip unzip library.
9+
10+The zip library unit is included in Lazarus 2.
11+
12+### Example
13+
14+Zip compression is in widespread use. It is also used to compress EPUB files.
15+
16+``` pascal
17+uses
18+ unzip,ziputils;
19+const cover = 'cover.jpeg';
20+var UnZipper : unzFile;
21+ epubfile, UnPackPathFile : String;
22+ zfinfos : unz_file_info_ptr;
23+ i : Integer;
24+ li_SizeRead,li_SizeWrite,li_TotalW : Longint;
25+ lb_FoundFile : Boolean;
26+ FBuffer : TExtFileBuffer;
27+ li_HandleDest : Integer;
28+begin
29+ epubfile :='/Your/Path/to/epub';
30+ UnPackPathFile :='/Your/Path/to/uncompressed/file';
31+ try
32+ UnZipper:=unzOpen(@epubfile[1]);
33+ if unzLocateFile(UnZipper,@cover[1],2)= UNZ_OK then
34+ try
35+ unzOpenCurrentFile(UnZipper);
36+ Getmem(zfinfos,SizeOf(zfinfos));
37+ unzGetCurrentFileInfo(UnZipper,zfinfos,@cover[1],SizeOf(cover),nil,0,nil,0);
38+ lb_FoundFile := False;
39+ if not FileExistsUTF8(UnPackPathFile)
40+ Then FileCreateUTF8(UnPackPathFile);
41+ li_HandleDest := FileOpenUTF8(UnPackPathFile, fmopenwrite );
42+ while not lb_FoundFile do
43+ begin
44+ li_SizeRead := unzReadCurrentFile(UnZipper,@FBuffer[0],high ( Fbuffer ) + 1);
45+ if li_SizeRead < high ( Fbuffer ) + 1 then lb_FoundFile := True;
46+ li_SizeWrite := Filewrite(li_HandleDest,Fbuffer,li_SizeRead);
47+ inc( li_TotalW, li_SizeWrite );
48+ end;
49+ Break;
50+ finally
51+ Freemem(zfinfos,SizeOf(zfinfos));
52+ end;
53+ finally
54+ try
55+ FileClose(li_HandleDest);
56+ finally
57+ unzCloseCurrentFile(UnZipper);
58+ unzClose(UnZipper);
59+ end;
60+ end;
61+end.
62+```
63+
64+## See also
65+
66+- [[zip|zip library link]]
67+- [[paszlib|paszlib: Object oriented zip file handling which does not require external libraries]]
68+
69+Go back to [[Package List|Packages List]]
70+
71+---
72+*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](/wiki-contact).*
73+Category: FPC
74+Category: Packages

Back to history