德爾福 2009 中的 Zlib (Zlib in Delphi 2009)


問題描述

德爾福 2009 中的 Zlib (Zlib in Delphi 2009)

I am upgrading a app to Delphi 2009. The app uses Soap and we compress the soap request and response streams using Zlib. This works fine in Delphi 2006 but not in Delphi 2009.

So I went back to Delphi 2006 and changed to use FastZlib. It all worked fine in Delphi2006 but does not work in Delphi 2009 and I get Decompress errors.

Has anyone else had this problem?

How do I go about fixing this?

Sandeep


參考解法

方法 1:

I just looked through the built-in Zlib.pas and it appears to have been updated for D2009 properly.  What's giving you problems?

方法 2:

In delphi 2006 I had following methods to compress and decompress using Zlib(from Delphi 2006)

procedure CompressStream(inpStream, outStream: TStream);
var
  InpBuf, OutBuf: Pointer;
  InpBytes, OutBytes: Integer;
begin
  InpBuf := nil;
  OutBuf := nil;
  try
    GetMem(InpBuf, inpStream.Size);
    inpStream.Position := 0;
    InpBytes := inpStream.Read(InpBuf^, inpStream.Size);
    CompressBuf(InpBuf, InpBytes, OutBuf, OutBytes);
    outStream.Write(OutBuf^, OutBytes);
  finally
    if InpBuf <> nil then FreeMem(InpBuf);
    if OutBuf <> nil then FreeMem(OutBuf);
  end;
end;


{ Decompress a stream }
procedure DecompressStream(inpStream, outStream: TStream);
var
  InpBuf, OutBuf: Pointer;
  OutBytes, sz: Integer;
begin
  InpBuf := nil;
  OutBuf := nil;
  sz     := inpStream.Size - inpStream.Position;
  if sz > 0 then 
    try
      GetMem(InpBuf, sz);
      inpStream.Read(InpBuf^, sz);
      DecompressBuf(InpBuf, sz, 0, OutBuf, OutBytes);
      outStream.Write(OutBuf^, OutBytes);
    finally
      if InpBuf <> nil then FreeMem(InpBuf);
      if OutBuf <> nil then FreeMem(OutBuf);
    end;
  outStream.Position := 0;
end;

What should I change for these to work in Delphi 2009?

方法 3:

Something that might be worth trying - compress your data, and then UUENCODE it, and on the other end, reverse the process.  This will detect if some code is not dealing with embedded zero's properly.  

Sorry, this is only a partial solution to help you narrow the problem down.

方法 4:

The original poster's was clear about the problem:  CompressBuf and DecompressBuf are GONE.

I also have a project that compiles just fine in D7, but fails to compile in D2010 because it can't find "CompressBuf" or "DecompressBuf".

A search using D7's very pleasant find command locates the routines at   c:\Program Files\Borland\Delphi7\Source\Rtl\Common\ZLib.pas

But searching with D2010's (awkward separate) "Find in Files" command fails to locate CompressBuf or DecompressBuf anywhere.

It's very disturbing that upgrading the IDE causes routines used and needed in projects to disappear!

方法 5:

in D2009 you can use ZCompress/ZDecompress instead of CompressBuf/DecompressBuf I test it and there is no problem.

(by Sandeep ChandraMason WheelerSandeepBen ZieglerKevin KillionXBasic3000)

參考文件

  1. Zlib in Delphi 2009 (CC BY-SA 3.0/4.0)

#compression #zlib #delphi #SOAP #delphi-2009






相關問題

CSS 壓縮和組合 / js 縮小 - 在運行時或構建時更好? (CSS compression & combining / js minification - Better to do at runtime or at build time?)

在javascript中壓縮包含音頻PCM數據的blob (compress blob containing audio PCM data in javascript)

如何提高@font-face 的加載性能 (How to improve loading performance of @font-face)

ServiceStack 流壓縮 (ServiceStack Stream Compression)

有沒有辦法讀取壓縮存檔的屬性? (Is there any way to read the properties of a Compressed Archive?)

德爾福 2009 中的 Zlib (Zlib in Delphi 2009)

SQL 2008開啟頁面壓縮後如何回收空間? (How to reclaim space after turning on page compression in SQL 2008?)

本機 Lua 中的高效可變字節數組 (Efficient mutable byte array in native Lua)

在 JavaScript 中壓縮純文本? (Compressing plaintext in JavaScript?)

如何遞歸壓縮文件夾? (How to zip a folder recursively?)

使用 GZIPOutputStream 壓縮字符串 (Compressing a string using GZIPOutputStream)

壓縮後 1 KB 可以容納多少文本? (How much text I can fit in 1 kilobyte with compression?)







留言討論