Bracket.Hosting.ZipArchiveDirectory.OpenInputFileStream C# (CSharp) Method

OpenInputFileStream() public method

public OpenInputFileStream ( string path, FileMode mode, FileAccess access, FileShare share, int bufferSize ) : Stream
path string
mode FileMode
access FileAccess
share FileShare
bufferSize int
return Stream
        public Stream OpenInputFileStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize)
        {
            //Unfortunately, the stream the zip reader uses is not seekable, and the DLR requires seekable
            //streams to be returnd from this method.
            ZipEntry entry = GetEntry(path);
            if (entry != null && entry.IsDirectory == false)
            {
                Stream reader = entry.OpenReader();
                if (reader.CanSeek && reader.CanRead)
                    new BufferedStream(reader);

                using (reader)
                {
                    return reader.ToMemoryStream();
                }
            }
            throw new DirectoryNotFoundException(GetFullName(path) + " cannot be found and cannot be opened for reading.");
        }

Usage Example

 public void OpenInputFileStreamShouldProvideStreamForRequestedFileInRoot()
 {
     //given
     var dir = new ZipArchiveDirectory("Fresh.zip");
     //when
     string result = null;
     using(var reader = new StreamReader(dir.OpenInputFileStream("file1.txt",FileMode.Open,FileAccess.Read,FileShare.Read,0)))
     {
         result = reader.ReadToEnd();
     }
     //then
     Assert.AreEqual("Well hello there little fellah!", result);
 }