如何将 char[] 对象读入 tango.io.compress.ZlibStream?
我有一个带有 Tango 的 D 程序,我正在尝试解压缩 gzip 压缩的字符串。不幸的是,我没有流,但压缩数据存储在 char[]
中。如何使用tangos tango.io.compress.ZlibStream
解压缩它?我需要另一个带有未压缩数据的 char[]
。
我已经尝试这个好几个小时了。我对探戈不太熟悉。
谢谢
编辑:我的代码如下所示:
char[] rawData; // decoded data goes here
Array array = new Array(e.value[4..(e.value.length-3)]); // e.value is a char[]
// array slice, castet to char[] is "H4sIAAAAAAAAA2NkYGBgHMWDBgMAjw2X0pABAAA="
// array.readable returns 40 (matches the above string)
// decoded string is expected to be 33 repeatitions of "AQAAAAEAAAABAAAA"
// followed by "AQAAAA=="
auto reader = new ZlibInput(array);
ubyte[1024] buffer;
reader.read(buffer); // throws Z_DATA_ERROR
I have a D program with Tango and I'm trying to uncompress a gzipped string. Unfortunately I don't have A stream to it, but the compressed data is stored in a char[]
. How can I uncompress it using tangos tango.io.compress.ZlibStream
? I need another char[]
with the uncompressed data.
I've been trying this for hours now. I'm not very familiar with tango.
Thank you
Edit: my code looks something like this:
char[] rawData; // decoded data goes here
Array array = new Array(e.value[4..(e.value.length-3)]); // e.value is a char[]
// array slice, castet to char[] is "H4sIAAAAAAAAA2NkYGBgHMWDBgMAjw2X0pABAAA="
// array.readable returns 40 (matches the above string)
// decoded string is expected to be 33 repeatitions of "AQAAAAEAAAABAAAA"
// followed by "AQAAAA=="
auto reader = new ZlibInput(array);
ubyte[1024] buffer;
reader.read(buffer); // throws Z_DATA_ERROR
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,没关系。看来,设计这种文件格式的人在使用 Base64 编码之前压缩了数据。我尝试解压缩仍然是 Base64 编码的数据。
当我使用 base64 解码字符串并在生成的 ubyte 数组上使用 gzip 时,它成功了!
对此感到抱歉。
well, nevermind. It appears, the guy who designed this file format compressed the data, before he encoded it with base64. I tried to decompress still base64 encoded data.
When I decoded the string with base64 and used gzip on the resulting ubyte array, it did the trick!
sorry about that.