Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2016-05

Using paszlib from fpc 3.0 with fpc and delphi 2007?

11 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bo Berglund

I have a project that is targeting both Linux (on Raspberry Pi) and Windows. It started in Delphi 2007 and is a command line utility.

It needs to use some zip compression of binary files, which must be readable both by the programs and the standard tools (WinZip etc).

I am going to finish the code in Delphi 2007 and then move the files over to FPC on the RPi and compile there.
So I need a zipper that can be used in both ends and since D2007 does not come with one built in but FPC does (paszlib), I figured I could copy the src dir from FPC over to Delphi and use that to compress my files.

Question before I start:
Does this work or must I add a number of conditionals or such in the code to make it work?
Also: which files are needed? It looks like the paszlib src dir has a subdir too with most of the files, is this necessary?

Bo Berglund Developer in Sweden

Reply by email

Marco van de Voort
to Bo Berglund

In our previous episode, Bo Berglund said:

Show quoted text 5 lines
over to FPC on the RPi and compile there. So I need a zipper that can be used in both ends and since D2007 does not come with one built in but FPC does (paszlib), I figured I could copy the src dir from FPC over to Delphi and use that to compress my files.

paszlib was originally a TP/D1 package that was afaik somewhat adapted to 32-bit delphi too.

FPC integrated this package about 15 years, and compatibility with other compilers is not guaranteed. The units are compiled in FPC mode, not even in TP or Delphi mode.

Also: which files are needed? It looks like the paszlib src dir has a subdir too with most of the files, is this necessary?

I would look for a ZIP codebase based on top of the zlib stream (TCompressionstream) interfaces.

These exist both in Delphi and FPC.

If you don't need the archiving aspect (multiple files into one), and only the compression, consider using gzip instead of ZIP, since it opens with fairly general tools like winzip, and TCompressionStream is enough.

Reply by email

Bo Berglund
to Marco van de Voort
I would look for a ZIP codebase based on top of the zlib stream (TCompressionstream) interfaces. These exist both in Delphi and FPC.

I checked in the D2007 help and it did show the TCompressionstream class so it does exist in my Delph version.

Next is trying to find a zipper based on that, I guess... When I google the first hit points to paszlib, so I am in a circle here. Paszlib wiki doc pages state that paszlib is used for TCompressionstream...
http://wiki.lazarus.freepascal.org/paszlib (second line)

If you don't need the archiving aspect (multiple files into one), and only the compression, consider using gzip instead of ZIP, since it opens with fairly general tools like winzip, and TCompressionStream is enough.

Well, the system I am working on collects data from a measuring instrument and saves the binary data (a memory image from the instrument) onto several types of bin files. Then it also converts the data to corresponding ASCII text files. Finally it is all stuffed into a single zipfile for transmission.
SoI need multiple files into one just like WinZip provides. Except done in my code.

Bo Berglund Developer in Sweden

Reply by email

Paul Breneman
to Bo Berglund: I have a project that is targeting both Linux (on Raspberry Pi) and Windows. It started…
Bo Berglund wrote 18 lines
I have a project that is targeting both Linux (on Raspberry Pi) and Windows. It started in Delphi 2007 and is a command line utility. It needs to use some zip compression of binary files, which must be readable both by the programs and the standard tools (WinZip etc). I am going to finish the code in Delphi 2007 and then move the files over to FPC on the RPi and compile there. So I need a zipper that can be used in both ends and since D2007 does not come with one built in but FPC does (paszlib), I figured I could copy the src dir from FPC over to Delphi and use that to compress my files. Question before I start: Does this work or must I add a number of conditionals or such in the code to make it work? Also: which files are needed? It looks like the paszlib src dir has a subdir too with most of the files, is this necessary?

You've probably considered Abbrevia:
http://wiki.lazarus.freepascal.org/FreePascalArchivePackage

Regards,
Paul
www.ControlPascal.com

Reply by email

Bo Berglund
to Paul Breneman
Paul Breneman wrote

Yes,
I got that as a suggestion over at the Embarcadero forum...

But when I downloaded it from Sourceforge it turned out to be really massive, some 700+ files and basically overwhelming.

I would like something simple, preferably built-in like TZipFile in later versions of Delphi. Or paszlib in FPC...
But I also would like to have it work both in Delphi and FPC/Lazarus.

Bo Berglund Developer in Sweden

Reply by email

Paul Breneman
to Bo Berglund
Bo Berglund wrote 16 lines
On Wed, 25 May 2016 08:21:54 -0500, Paul Breneman wrote: > You've probably considered Abbrevia: > http://wiki.lazarus.freepascal.org/FreePascalArchivePackage > Yes, I got that as a suggestion over at the Embarcadero forum... But when I downloaded it from Sourceforge it turned out to be really massive, some 700+ files and basically overwhelming. I would like something simple, preferably built-in like TZipFile in later versions of Delphi. Or paszlib in FPC... But I also would like to have it work both in Delphi and FPC/Lazarus.

Yes, it may be large as it does a *lot* of things. I know that people invested a *lot* of work in improving it after it went open source, so if you can figure out what part to use it should work good in Delphi and FPC.

Regards,
Paul
www.ControlPascal.com

Reply by email

Bo Berglund
to Graeme Geldenhuys
Graeme Geldenhuys wrote 8 lines
On 2016-05-25 15:58, Paul Breneman wrote: > so > if you can figure out what part to use it should work good in Delphi and > FPC. I can confirm Abbrevia worked well for a Delphi/FPC project I worked on a couple years ago. I also don't recall it being difficult to use.

OK, I will see if I can work with it without installing the complete package. Maybe I can just figure out the needed units and go with these. If so I will post the result here (I mean which units were needed for a minimum file write).

Bo Berglund Developer in Sweden

Reply by email

Graeme Geldenhuys
to Bo Berglund
Bo Berglund wrote
I will see if I can work with it without installing the complete package. Maybe I can just figure out the needed units and go with these.

That's exactly what we did too. We didn't even bother installing it (visible in the Component Palette of the IDE). We simply added the unit paths to our projects and use the classes and units we needed.

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp

Reply by email

Bo Berglund
to Bo Berglund: On Wed, 25 May 2016 21:59:21 +0100, Graeme Geldenhuys OK, I will see if I can work with…
Bo Berglund wrote
OK, I will see if I can work with Abbrevia without installing the complete package. Maybe I can just figure out the needed units and go with these. If so I will post the result here (I mean which units were needed for a minimum file write).

I have a solution now, but I got a suggestion from the Embarcadero forum to check Synopse and there I found a single file (plus an inc) solution to my problem.
I downloaded the PasZip.pas and Synopse.inc files from this location: http://synopse.info/fossil/dir?ci=tip
(Actually the inc file would not download so I copied the contents from the website display instead into a file)
This is the function I ended up with and it works just fine:

function TSSCommHandler.ZipFiles(TargetFile: string; FileList:
TStringList): boolean;
{This function uses the Synopse files PasZip.pas and Synopse.inc to
create the zipfile.
Files were obtained from http://synopse.info/fossil/dir?ci=tip}
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;

I am only interested in the creation of the zipfile, but there is a reader class available too.

Bo Berglund Developer in Sweden

Reply by email

Bo Berglund
to Bo Berglund
Bo Berglund wrote 44 lines
I got a suggestion from the Embarcadero forum to check Synopse and there I found a single file (plus an inc) solution to my problem. I downloaded the PasZip.pas and Synopse.inc files from this location: http://synopse.info/fossil/dir?ci=tip This is the function I ended up with and it works just fine: function TSSCommHandler.ZipFiles(TargetFile: string; FileList: TStringList): boolean; {This function uses the Synopse files PasZip.pas and Synopse.inc to create the zipfile. Files were obtained from http://synopse.info/fossil/dir?ci=tip} 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; I am only interested in the creation of the zipfile, but there is a reader class available too.

I have a question on regards to this PasZip unit:

In the function above the supplied files wind up in the zip archive as intended, but I would like to improve it just a little bit by also setting the extract dir to the name of the zipfile. So if the zip is named PP1.zip I want the contents to be extracted to subdir PP1 in the dir where the zip is located.

Is there anyone here who has used PasZip.pas from Synopse and have a solution?

Bo Berglund Developer in Sweden

Reply by email