-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…7479 * AutoCloseOnReadCompleteStream (cherry picked from commit 8dd1316) * Ensure old response content is closed out for hot reload (cherry picked from commit ebdfdf4) * PR Feedback (cherry picked from commit 122426c)
- Loading branch information
1 parent
f097f92
commit a8e4d78
Showing
4 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/BlazorWebView/src/SharedSource/AutoCloseOnReadCompleteStream.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#if WEBVIEW2_WINFORMS || WEBVIEW2_WPF | ||
|
||
using System.IO; | ||
|
||
namespace Microsoft.AspNetCore.Components.WebView.WebView2 | ||
{ | ||
internal class AutoCloseOnReadCompleteStream : Stream | ||
{ | ||
private readonly Stream _baseStream; | ||
|
||
public AutoCloseOnReadCompleteStream(Stream baseStream) | ||
{ | ||
_baseStream = baseStream; | ||
} | ||
|
||
public override bool CanRead => _baseStream.CanRead; | ||
|
||
public override bool CanSeek => _baseStream.CanSeek; | ||
|
||
public override bool CanWrite => _baseStream.CanWrite; | ||
|
||
public override long Length => _baseStream.Length; | ||
|
||
public override long Position { get => _baseStream.Position; set => _baseStream.Position = value; } | ||
|
||
public override void Flush() => _baseStream.Flush(); | ||
|
||
public override int Read(byte[] buffer, int offset, int count) | ||
{ | ||
var bytesRead = _baseStream.Read(buffer, offset, count); | ||
|
||
// Stream.Read only returns 0 when it has reached the end of stream | ||
// and no further bytes are expected. Otherwise it blocks until | ||
// one or more (and at most count) bytes can be read. | ||
if (bytesRead == 0) | ||
{ | ||
_baseStream.Close(); | ||
} | ||
|
||
return bytesRead; | ||
} | ||
|
||
public override long Seek(long offset, SeekOrigin origin) => _baseStream.Seek(offset, origin); | ||
|
||
public override void SetLength(long value) => _baseStream.SetLength(value); | ||
|
||
public override void Write(byte[] buffer, int offset, int count) => _baseStream.Write(buffer, offset, count); | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters