On Thu, 14 Jul 2016, Bo Berglund wrote:
On Thu, 14 Jul 2016 10:09:36 +0100, Graeme Geldenhuys
<mailingli...@geldenhuys.co.uk> wrote:
If you have the time, it might be worth abstracting out the zip reading
functionality so you can swap out the actual compression components used
as needed. This will allow your application to change compression tools
in future, without your application code needing any changes. This is
always a good design philosophy when it comes to using 3rd party components.
While working at a previous employer we use the TurboPower suite of
compression components under Windows and Linux with great success, but
could also swap it out for the FPC included ZLib unit.
Well,
I do have the zip *writing* in one single place as a method for the
class that handles the communication. It gets a target zipfile name
and a stringlist containing the files to zip as arguments, so that is
pretty portable.
Here is how it looks like:
uses PasZip;
function TSSCommHandler.ZipFiles(TargetFile: string; FileList:
TStringList): boolean;
var
ZW: TZipWrite;
i: integer;
FileName: string;
begin
Result := false;
ZW := TZipWrite.Create(TargetFile);
try
try
for i := 0 to FileList.Count-1 do
begin
FileName := FileList[i];
if not FileExists(FileName) then Continue;
ZW.AddDeflated(FileName);
end;
Result := true;
except
on E: Exception do
begin
FLastError := 'Zip error: ' + E.Message;
exit;
end;
end;
finally
ZW.Free;
end;
end;
What I need elsewhere in the code is not depening on PasZip, the call
to create the zipfile is simply:
ZipFiles(TargetFile, FileList);
So with the proper set of conditionals I could have different
implementations of this method for Windows and Linux.
Do you have an example of how to do the above with FPC ZLib?
You can find this almost verbatim in the examples of paszlib, using the
zipper unit.
Michael.
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal