HPW
New Member
Posts: 14
|
Post by HPW on Mar 7, 2004 16:10:00 GMT -5
My zip contains a textfile with this line:
"This bla bla bla"
But on UnZip I get some more characters:
"This bla bla blaìEõ"
From the help:
If you pass in Buffer with a value of nil then Buffer will be allocated at exactly the size of the uncompressed file by VCLUnZip and passed back to you. It will then be your responsibility to free that memory using a call to FreeMem.
So here my function:
FUNCTION UnZipString( const ZipNamestr, FileNamestr, Pword : PChar) : PChar; stdcall; VAR tmpstring : STRING; resstring : PChar; zipstring : STRING; filestring : STRING; exestring : STRING; VCLZip1 : TVclZip; begin zipstring := StringReplace (ZipNamestr,'/','\',[rfReplaceAll, rfIgnoreCase]); filestring := StringReplace (FileNamestr,'/','\',[rfReplaceAll, rfIgnoreCase]); VCLZip1 := TVclZip.Create(nil); With VCLZip1 do begin ZipName := zipstring; Password := Pword; resstring := nil; UnZipToBuffer(resstring, filestring ); tmpstring := PChar(resstring); { showmessage ('['+PChar(resstring)+']');} FreeMem(resstring); end; VCLZip1.Free; SetStr( Result, tmpstring); end;
|
|
|
Post by Kevin on Mar 8, 2004 8:00:12 GMT -5
Can you show me your zipping code too?
Kevin
|
|
HPW
New Member
Posts: 14
|
Post by HPW on Mar 8, 2004 11:30:45 GMT -5
No problem.
But I have also checked the zip with winzip. It opens and look fine. Only my string and nothing else. So I guess it is something with my Unzip wrong.
FUNCTION ZipString( const ZipNamestr, FileNamestr, InStringVar, Pword : PChar) : PChar; stdcall; VAR tmpstring : STRING; zipstring : STRING; filestring : STRING; VCLZip1 : TVclZip; begin zipstring := StringReplace (ZipNamestr,'/','\',[rfReplaceAll, rfIgnoreCase]); filestring := StringReplace (FileNamestr,'/','\',[rfReplaceAll, rfIgnoreCase]); VCLZip1 := TVclZip.Create(nil); With VCLZip1 do begin ZipName := zipstring; Password := Pword; StorePaths := True; PackLevel := 6; tmpstring := IntToStr(ZipFromBuffer(InStringVar, Length(InStringVar), filestring)); end; VCLZip1.Free; SetStr( Result, tmpstring); end;
|
|
|
Post by Kevin on Mar 8, 2004 22:53:44 GMT -5
I don't have a chance to investigate it right now, but what happens if you pre-allocate the buffer to the right size instead of passing in nil?
I will have a chance to look at it more closely tomorrow.
Kevin
|
|
HPW
New Member
Posts: 14
|
Post by HPW on Mar 9, 2004 7:00:03 GMT -5
I will also do further tests and have a deeper look at your sample code.
Of cource it would be nice to get this way working, because it is the easyest way to do it without any preprocessing with a filename.
|
|
|
Post by Kevin on Mar 9, 2004 9:51:06 GMT -5
It looks like the problem here is that you are expecting VCLZip to return a null terminated buffer but it does not. VCLZip only allocates exactly UncompressedSize bytes. It does not allocate an extra byte for creating a null terminated string. You have two choices. One is to allocate the buffer yourself and pass it in. To do this you would need to find the file you are wanting to extract within the indexed properties by checking FileName (or FullName if you have pathnames stored in the archive). Once you have that, you can get UncompressedSize and allocate your buffer with a length of Uncompressed+1.
The other option requires modifying VCLZip code. To do this, open up KPUNZIPP.PAS and find the following code at about line 750 :
If (MemBuffer = nil) then begin GetMem( MemBuffer, file_info.uncompressed_size); AllocatedBuffer := True; end;
and change it to this:
If (MemBuffer = nil) then begin GetMem( MemBuffer, file_info.uncompressed_size+1); ZeroMemory(MemBuffer,file_info.uncompressed_size+1); AllocatedBuffer := True; end;
I haven't had a chance to test this code change yet but I believe it should work. Let me know.
I will consider whether it makes more sense to make this a permenant change to VCLZip or not.
Kevin
|
|
HPW
New Member
Posts: 14
|
Post by HPW on Mar 9, 2004 13:38:18 GMT -5
Kevin,
Thanks a lot, the changed code works like a charm. Now it is easy to pass the PChar and get it back. Excellent support for an excellent product. I have to dig deeper into your product.
:-))
Hans-Peter
|
|
HPW
New Member
Posts: 14
|
Post by HPW on Mar 29, 2006 11:30:34 GMT -5
Kevin,
Now after I upgrade to Pro 3.06 can I expect that this will work in Pro or must I change something again.
Hans-Peter
|
|
|
Post by Kevin on Apr 13, 2006 21:47:31 GMT -5
If I remember correctly, I don't believe I made this change permanant in 3.06.
Kevin
|
|
HPW
New Member
Posts: 14
|
Post by HPW on Apr 15, 2006 7:51:25 GMT -5
Thanks for the info. I will check again.
|
|
|
Post by Kevin on Mar 22, 2008 8:49:07 GMT -5
I have added this into the code and it will be part of the next release.
Kevin
|
|