#1 2012-05-08 15:35:26

PhilW
Member
Registered: 2012-05-08
Posts: 2

SynZip - uncompress zip data contained in a string

Hello,

Firstly, I would like to thank everybody at Synopse for making such wonderful software opensource.

I have Delphi XE, and use the SynZip component for all my zip/unzip tasks in my programs; I have a requirement which I could do with some advice, please.

I am retrieving a zip archive via a webservice, the (external dll) function returning the data in a WideString variable.

Something like this, for instance:
---------------a bit of code-------------
var
   MyWoInterop: IWoWebServiceInterop;
   s: WideString;
begin
   MyWoInterop  := CreateComObject(CLASS_WoWebServiceInterop) as IWoWebServiceInterop;
   Screen.Cursor := crHourGlass;
   try try
      s := MyWoInterop.GetStockProducts(DEF_WEBSITE);
   except
      //...
   end;
   finally
      //...
   end;
---------------------------------------

My question is, how can I uncompress the zip data held in the Widestring variable.  SynZip has a "UncompressString" method, but the code says :
/// uncompress some data, with a proprietary format (including CRC)
// - return '' in case of a decompression failure
function UncompressString(const data: RawByteString) : RawByteString;

which looks as it will not handle zip data, even if the cast from WideString to RawByteString is valid.

What else could I try? Any advice please?
Thanks for your help
Kind regards
PhilW.

Offline

#2 2012-05-09 05:14:24

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,232
Website

Re: SynZip - uncompress zip data contained in a string

First of all, CompressString/UnCompressString is a proprietary format, not the official ZIP format.
So it won't be able to handle a ZIP archive.

I think a string is not the right way of storing some binary data, like a ZIP archive.

How is the string created by IWoWebServiceInterop.GetStockProducts ?
I guess this value is created from a DB BLOB.
If the WideString is just a mapping of the BLOB bytes, you may be able to use pointer(WideString) to access the ZIP content memory buffer.
If the WideString is created from the concatenation of all BLOB bytes, you may be able to retrieve the ZIP content as such:

var zip: RawByteString;
  s: WideString;
begin
  ...
  SetLength(zip,length(s));
  for i := 0 to length(s)-1 do
    PByteArray(zip)[i] := PWordArray(s)[i];
  // now zip contains the BLOB bytes
  ...

If you need to use WideString for the process, I recommend serialize the content as true ASCII chars (to avoid any ASCII/UNICODE issue).
That is, use either HexaDecimal either Base64 encoding.

Offline

#3 2012-05-09 10:01:54

PhilW
Member
Registered: 2012-05-08
Posts: 2

Re: SynZip - uncompress zip data contained in a string

Hi, ab,

Thank you for the quick and considered response. I was struggling to visualize how the data was being stored in the WideString variable; your comments have clarified the possibilities, especially the code example,  thank you.

I now know what question to ask the (external) software house about their webservice library - I'll let everyone know how I get on.

Many thanks
PhilW.

Offline

Board footer

Powered by FluxBB