1

我需要解码使用 7zip 创建的 .xz 文件。压缩算法是 LZMA2。我应该如何使用 7zip SDK for C# 来解决这个问题?我已经尝试过使用此代码,但它不起作用:

var coder = new SevenZip.Compression.LZMA.Decoder();
var input = new MemoryStream(); // filled with byte array of .xz file
var output = new MemoryStream();

// Read the decoder properties
byte[] properties = new byte[5];
zipFile.Read(properties, 0, 5);

// Read in the decompress file size.
byte[] fileLengthBytes = new byte[8];
zipFile.Read(fileLengthBytes, 0, 8);
long fileLength = BitConverter.ToInt64(fileLengthBytes, 0);

coder.SetDecoderProperties(properties); // this throws exception
coder.Code(zipFile, output, zipFile.Length, fileLength, null);
output.Flush();
output.Close();

我标记了导致异常的行。

4

0 回答 0