1
我正在測試一些代碼。我堅持以下。我曾寫過text
,壓縮流的長度總是10?我究竟做錯了什麼?爲什麼壓縮流的長度始終爲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);
http://stackoverflow.com/questions/34566559/is-it-possible-to-get-length-of-closed-memory-stream – MethodMan
@MethodMan目前我沒有關閉任何東西。它不應該是 –
但是@MethodMan是正確的 - 直到你關閉它,壓縮流不知道你已經寫完了 - 所以無法完成它的壓縮算法。 – PhillipH