私はC#で軽量のプロキシを書いていました。gzip contentEncoding をデコードしていたときに、小さな buffer-size (4096) を使用すると、入力のサイズに応じてストリームが部分的にデコードされることに気付きました。それは私のコードのバグですか、それともそれを機能させるために必要なものですか? バッファーを 10 MB に設定しました。問題なく動作しますが、軽量プロキシを作成するという私の目的が無効になります。
response = webEx.Response as HttpWebResponse;
Stream input = response.GetResponseStream();
//some other operations on response header
//calling DecompressGzip here
private static string DecompressGzip(Stream input, Encoding e)
{
StringBuilder sb = new StringBuilder();
using (Ionic.Zlib.GZipStream decompressor = new Ionic.Zlib.GZipStream(input, Ionic.Zlib.CompressionMode.Decompress))
{
// works okay for [1024*1024*8];
byte[] buffer = new byte[4096];
int n = 0;
do
{
n = decompressor.Read(buffer, 0, buffer.Length);
if (n > 0)
{
sb.Append(e.GetString(buffer));
}
} while (n > 0);
}
return sb.ToString();
}