使用 TZCompressionStream 截断数据
我有以下声明:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须释放 TZCompressionStream 将剩余字节刷新到内存流中。
You have to Free the TZCompressionStream to flush the remaining bytes into the memory stream.