为什么压缩流的长度总是10?

时间:2016-07-12 11:12:41

标签: c# gzipstream

我正在测试一些代码。我坚持以下。我写的是text,压缩流的长度总是10?我做错了什么?

var inStream = new MemoryStream();

var inWriter = new StreamWriter(inStream);

str text = "HelloWorldsasdfghj123455667880fgsjfhdfasdferrbvbyjun hbwecwcxqsz    edcrgvebrjnuj5juerqwetsrgfggshurhtnbvzkfjhguhgrgal;kjhao;rhl;zkfhg;aorihghg;oahrgarhguhh';aaeaeiaijeihjrhfidfhfidfidhh953453453";
inWriter.WriteLine(text);

inWriter.Flush();
inStream.Position = 0;

var outStream = new MemoryStream();
var compressStream = new GZipStream(outStream, CompressionMode.Compress);
inStream.CopyTo(compressStream);

compressStream.Flush();
outStream.Flush();
compressStream.Flush();

outStream.Position = 0;

Console.WriteLine(outStream.Position);
Console.WriteLine(outStream.Length);

1 个答案:

答案 0 :(得分:2)

直到你关闭它,压缩流不知道你已经写完了 - 所以无法完成它的压缩算法。刷新刷新它可以刷新的部分,但是直到它被告知你已经完成添加新的字节,它才能刷新它的最后一个压缩数据包。