为什么压缩流的长度总是 10?
Why the length of zipped stream is always 10?
我正在测试一些代码。我坚持以下内容。我怎么写 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);
在您关闭它之前,压缩流不知道您已经完成写入 - 因此无法完成其压缩算法。刷新会刷新它可以刷新的那些部分,但是直到它被告知您已完成添加新字节,它才能刷新其最后一个压缩数据包。
我正在测试一些代码。我坚持以下内容。我怎么写 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);
在您关闭它之前,压缩流不知道您已经完成写入 - 因此无法完成其压缩算法。刷新会刷新它可以刷新的那些部分,但是直到它被告知您已完成添加新字节,它才能刷新其最后一个压缩数据包。