Exemplo n.º 1
0
        public static StreamReader OpenTextStripComments(this FileInfo fileInfo, bool allowGzip = true)
        {
            if (fileInfo == null)
            {
                throw new ArgumentNullException("fileInfo");
            }


            if (allowGzip && (
                fileInfo.Extension.Equals(".gz", StringComparison.CurrentCultureIgnoreCase) ||
                fileInfo.Extension.Equals(".gzip", StringComparison.CurrentCultureIgnoreCase)))
            {
                FileStream infile = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.Read);
                GZipStream zipStream = new GZipStream(infile, CompressionMode.Decompress);
                StreamReader reader = zipStream.StripComments();

                return reader;
            }
            else
            {
                return new CommentedStreamReader(fileInfo);
            }
        }