使用 TZCompressionStream 截断数据

发布于 2024-12-27 20:58:28 字数 828 浏览 0 评论 0原文

我有以下声明:

stmCompressor: TZCompressionStream;
stmCompressed: TMemoryStream;
stmBlob: TStream;

我有以下代码:

stmBlob := qry.CreateBlobStream(qry.FieldByName(sFieldName), bmRead);
stmCompressed := TMemoryStream.Create;
stmCompressor := TZCompressionStream.Create(stmCompressed); 
stmBlob.Position := 0;
stmCompressor.CopyFrom(stmBlob, stmBlob.Size);
stmCompressed.Position := 0;
stmCompressed.SaveToFile('C:\Temp\CompressedData2.zip');

我正在尝试压缩数据库中的图像数据并将结果放入内存流 stmCompressed 中。然后我将 stmCompressed 保存到一个文件中,以便我可以检查结果。结果似乎是应有的形式的截断形式。如果压缩数据大于 80000H,则文件将被截断为该大小。如果数据大于 B0000H,则文件将被截断为该大小。

有趣的是,如果我将 stmCompressed 从 TMemoryStream 更改为 TFileStream,那么它可以完美运行(代码不完全相同 - 如果有帮助,我可以发布它)。

我需要将结果保存在内存流中,因此我将不胜感激任何人都可以提供的帮助。我正在使用 XE2 附带的标准 ZLib 库。

谢谢。

I have the following declarations:

stmCompressor: TZCompressionStream;
stmCompressed: TMemoryStream;
stmBlob: TStream;

I have the following code:

stmBlob := qry.CreateBlobStream(qry.FieldByName(sFieldName), bmRead);
stmCompressed := TMemoryStream.Create;
stmCompressor := TZCompressionStream.Create(stmCompressed); 
stmBlob.Position := 0;
stmCompressor.CopyFrom(stmBlob, stmBlob.Size);
stmCompressed.Position := 0;
stmCompressed.SaveToFile('C:\Temp\CompressedData2.zip');

I am trying to compress image data from the database and place the result in the memory stream stmCompressed. I am then saving stmCompressed into a file so that I can check the result. The result appears to be a truncated form of what it should be. If the compressed data is larger than 80000H then the file is truncated to this size. If the data is larger than B0000H then the file is truncated to this size.

The funny thing is that if I change stmCompressed from a TMemoryStream to a TFileStream then it works perfectly (the code is not exactly the same - I can post it if it would help).

I need the result to be in a memory stream, so I would appreciate any help anyone can offer. I'm using the standard ZLib library that comes with XE2.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我纯我任性 2025-01-03 20:58:28

您必须释放 TZCompressionStream 将剩余字节刷新到内存流中。

You have to Free the TZCompressionStream to flush the remaining bytes into the memory stream.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文