如何将StreamReader流重置为开头?

时间:2016-03-01 05:18:04

标签: c# zip streamreader ziparchive

我已经提到了App on Github,但无法弄清楚这个问题。

这是读取zip文件中特定文件流的代码。这里有两个不同的zip文件中的两个文件流。现在我需要比较流。

我无法将BaseFileReader流的流设置为流的开头。

using (FileStream BaseZipToOpen = new FileStream(BaseArchive,FileMode.Open) , CurrentZipToOpen = new FileStream(CurrentArchive,FileMode.Open))
{
    using (ZipArchive BaseZip = new ZipArchive(BaseZipToOpen, ZipArchiveMode.Read), CurrentZip = new ZipArchive(CurrentZipToOpen, ZipArchiveMode.Read))
    {
         ZipArchiveEntry BaseFile = BaseZip.GetEntry(requiredFile);
         ZipArchiveEntry CurrentFile = CurrentZip.GetEntry(requiredFile);

         using (StreamReader BaseFileReader = new StreamReader(BaseFile.Open()), CurrentFileReader = new StreamReader(CurrentFile.Open()))
         {
            string baseFileLine, currentFileLine;

            while (!CurrentFileReader.EndOfStream)
            {
                currentFileLine = CurrentFileReader.ReadLine();

                while (!BaseFileReader.EndOfStream)
                {
                    baseFileLine = BaseFileReader.ReadLine();

                    if (!currentFileLine.Equals(baseFileLine))
                    {
                        difference = true;
                    }
                    else 
                    {
                        difference = false;
                        break;
                    }
                }

                // how to reset BaseFileReader Stream to beginning?
                BaseZipToOpen.Seek(0, SeekOrigin.Begin); //This is not working
            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

您可以使用

    FileStream stream = new FileStream();
    stream.Position = 0;