With FileStreamResult, how is the MemoryStream closed?

后端 未结 2 1596
情深已故
情深已故 2021-01-07 16:16

The following code works, but I\'m wondering if the MemoryStream created is closed properly. How should this be performed or does FileStreamResult

2条回答
  •  旧巷少年郎
    2021-01-07 16:54

    You have access to source code, so you can check yourself ;-)

    protected override void WriteFile(HttpResponseBase response)
    {
      Stream outputStream = response.OutputStream;
      using (this.FileStream)
      {
        byte[] buffer = new byte[4096];
        while (true)
        {
          int count = this.FileStream.Read(buffer, 0, 4096);
          if (count != 0)
            outputStream.Write(buffer, 0, count);
          else
            break;
        }
      }
    }
    

提交回复
热议问题