关于c#:解压缩Zlib数据

Decompress Zlib data

我目前正在尝试从Zlib压缩的.mat文件中解压缩一些字节。
我从MAT文件格式中读取了第1-12页的第3段,它告诉我们.mat文件中的字节是由Zlib压缩的。

因此,我的问题是C#是否具有一些可以解压缩字节的API或库。
如果我有一组像

这样的字节

1
2
6236 20e6 0062 1606 0860 85f2 1981 980b
4cb3 30e4 25e6 a60a 40f9 2545 9989 39f1

然后将它们加载到SByte数组中,如何解压缩它们?

我还在线检查了一些图书馆。看来他们可以做的是解压缩整个文件,而不是某些字节....

关于这方面,我很新。任何帮助表示赞赏。


您可以使用SharpZipLib中的InflaterInputStream.mat文件的标头长度为0x88,因此您必须跳过它。我从此处获取了示例文件SampleMatlabMatDataFiles.zip。

1
2
3
4
5
6
byte[] data = File.ReadAllBytes("c.mat").Skip(0x88).ToArray();
byte[] decompressedData = new byte[10000];
int decompressedLength = 0;
using (MemoryStream memory = new MemoryStream(data))
using (InflaterInputStream inflater = new InflaterInputStream(memory))
    decompressedLength = inflater.Read(decompressedData, 0, decompressedData.Length);