Difference between revisions of "paszlib"

From Free Pascal wiki
Jump to navigationJump to search
(Simplified sentences, see also)
Line 1: Line 1:
 
{{paszlib}}
 
{{paszlib}}
  
'''paszlib''' is a Pascal conversion (thus without dependancies) of the standard zlib library, implemented by Jacques Nomssi Nzali (his old homepage is dead, see a continuation of the project [http://sageshome.net/oss/paszlib-sg.php here]) It is used in the FCL to implement the TCompressionStream class. The main unit of this package is '''paszlib'''. there are other, auxiliary units, but the only unit that needs to be included in a typical program is this one. (View interface)  
+
'''paszlib''' is a Pascal conversion of the standard zlib library: you don't need any external dependencies. It was implemented by Jacques Nomssi Nzali (his old homepage is dead, see a continuation of the project [http://sageshome.net/oss/paszlib-sg.php here]) It is used in the FCL to implement the TCompressionStream class. The main unit of this package is '''paszlib'''. There are other, auxiliary units, but the only unit that needs to be included in a typical program is this one. (View interface)  
  
 
==TZipper==
 
==TZipper==
 
+
TZipper implements support for compressing and decmpressing .zip files, but does not extract all zip compression methods.
 
 
  
 
===Examples===
 
===Examples===
Line 11: Line 10:
 
====Zip files====
 
====Zip files====
  
Create zip file named as parameter 1 from files entered as rest parameters.
+
Create a zip file named as parameter 1. Treats all other parameters as filenames to add.
  
 
<syntaxhighlight>uses
 
<syntaxhighlight>uses
Line 49: Line 48:
 
end.</syntaxhighlight>
 
end.</syntaxhighlight>
  
More examples can be found in FPC source directory [http://svn.freepascal.org/svn/fpc/trunk/packages/paszlib/examples/]
+
More examples can be found in the FPC source directory [http://svn.freepascal.org/svn/fpc/trunk/packages/paszlib/examples/]
  
 
====Unzip file to a stream====
 
====Unzip file to a stream====
In Lazarus, drop a TMemo, TButton, TEdit and TFileNameEdit on a form. Clicking the button will extract the file specified in the Edit box from the zipfile in FileNameEdit and display the content in Memo.
+
In Lazarus, drop a TMemo, TButton, TEdit and TFileNameEdit on a form. Clicking the button will read the zip file in FileNameEdit, extract the file specified in the Edit box, and display the content in Memo.
  
 
<syntaxhighlight>uses
 
<syntaxhighlight>uses
Line 98: Line 97:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Go to back [[Package_List|Packages List]]
+
== See also ==
 +
[[unzip|unzip]]
 +
 
 +
Go back to [[Package_List|Packages List]]

Revision as of 10:29, 6 June 2012

Deutsch (de) English (en) 한국어 (ko) polski (pl) русский (ru)

paszlib is a Pascal conversion of the standard zlib library: you don't need any external dependencies. It was implemented by Jacques Nomssi Nzali (his old homepage is dead, see a continuation of the project here) It is used in the FCL to implement the TCompressionStream class. The main unit of this package is paszlib. There are other, auxiliary units, but the only unit that needs to be included in a typical program is this one. (View interface)

TZipper

TZipper implements support for compressing and decmpressing .zip files, but does not extract all zip compression methods.

Examples

Zip files

Create a zip file named as parameter 1. Treats all other parameters as filenames to add.

uses
  Zipper;
var
  Zipper: TZipper;
begin
  try
    Zipper := TZipper.Create;
    Zipper.FileName := ParamStr(1);
    for I := 2 to ParamCount do
      Zipper.Entries.AddFileEntry(ParamStr(I), ParamStr(I));
    Zipper.ZipAllFiles;
  finally
    Zipper.Free;
  end;
end.

Unzip files

Unzip all files contained in archive with name given by ZipFilePath to directory entered as UnzippedFolderName.

uses
  Zipper;
var
  UnZipper: TUnZipper;
begin
  UnZipper := TUnZipper.Create;
  try    
    UnZipper.FileName := ZipFilePath;
    UnZipper.OutputPath := UnzippedFolderName;
    UnZipper.Examine;
    UnZipper.UnZipAllFiles;
  finally
    UnZipper.Free;
  end;
end.

More examples can be found in the FPC source directory [1]

Unzip file to a stream

In Lazarus, drop a TMemo, TButton, TEdit and TFileNameEdit on a form. Clicking the button will read the zip file in FileNameEdit, extract the file specified in the Edit box, and display the content in Memo.

uses
  Zipper;

...

procedure TForm1.Button1Click(Sender: TObject);
begin
  ExtractFileFromZip(FileNameEdit1.FileName,Edit1.Text);
end;

procedure TForm1.DoCreateOutZipStream(Sender: TObject; var AStream: TStream;
  AItem: TFullZipFileEntry);
begin
  AStream:=TMemorystream.Create;
end;

procedure TForm1.DoDoneOutZipStream(Sender: TObject; var AStream: TStream;
  AItem: TFullZipFileEntry);
begin
  AStream.Position:=0;
  Memo1.lines.LoadFromStream(Astream);
  Astream.Free;
end;

procedure TForm1.ExtractFileFromZip(ZipName, FileName: string);
var
  ZipFile: TUnZipper;
  sl:TStringList;
begin
  sl:=TStringList.Create;
  sl.Add(FileName);
  ZipFile := TUnZipper.Create;
  try
    ZipFile.FileName := ZipName;
    ZipFile.OnCreateStream := @DoCreateOutZipStream;
    ZipFile.OnDoneStream:=@DoDoneOutZipStream;
    ZipFile.UnZipFiles(sl);
  finally
    ZipFile.Free;
    sl.Free;
  end;
end;

See also

unzip

Go back to Packages List