Esempio n. 1
0
        static Func<bool> GzipFinished(GZipStream ins)
        {
            try
            {
                var g = ins.GetType().GetField("deflateStream", BindingFlags.Instance | BindingFlags.NonPublic);
                if (g == null) return null;
                var s = (DeflateStream)g.GetValue(ins);
                if (s == null) return null;
                var f = s.GetType().GetField("inflater", BindingFlags.Instance | BindingFlags.NonPublic);
                if (f == null) return null;
                var fo = f.GetValue(s);
                var avf = fo.GetType().GetProperty("AvailableOutput");
                var bterm = fo.GetType().GetField("bfinal", BindingFlags.Instance | BindingFlags.NonPublic);
                if (avf == null || bterm == null) return null;

                return () =>
                    (int) avf.GetValue(fo, new object[0]) == 0 // no more data in decode buffer
                    && (int)bterm.GetValue(fo) == 1; // have reached end of stream

            }
            catch (Exception)
            {
                return null;
            }
        }