我正在使用 SevenZipSharp 库来压缩然后解压缩包含一个简单序列化对象的 MemoryStream。但是,压缩流和解压缩流的长度不同。
从下面运行的代码中我得到
输入长度:174 输出长度:338
(SevenZipSharp dll 包含在参考中,7z.dll 包含在项目输出中)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace DataTransmission {
class Program {
static void Main(string[] args)
{
SevenZip.SevenZipCompressor compressor = new SevenZip.SevenZipCompressor();
//compressor.CompressionMethod = SevenZip.CompressionMethod.Lzma2;
//compressor.CompressionLevel = SevenZip.CompressionLevel.Normal;
MemoryStream inputStream = new MemoryStream();
Person me = new Person("John", "Smith");
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(inputStream, me);
Int32 inputStreamLength = (Int32)inputStream.Length;
MemoryStream outputStream = new MemoryStream();
compressor.CompressStream(inputStream, outputStream);
SevenZip.SevenZipExtractor decompressor = new SevenZip.SevenZipExtractor(outputStream);
decompressor.ExtractFile(0, outputStream);
Int32 outputStreamLength = (Int32)outputStream.Length;
Console.WriteLine("Input length: {0}", inputStreamLength);
Console.WriteLine("Output length: {0}", outputStreamLength);
Console.ReadLine();
}
}
[Serializable]
public class Person {
public string firstName;
public string lastName;
public Person(string fname, string lname) {
firstName = fname;
lastName = lname;
}
}
}
谁能帮我解释为什么会这样?
谢谢,