-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
1,585 additions
and
1,085 deletions.
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
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 |
---|---|---|
@@ -1,47 +1,58 @@ | ||
using System.IO; | ||
|
||
namespace Microsoft.AspNetCore.Components.WebView.WebView2 | ||
namespace Microsoft.AspNetCore.Components.WebView.WebView2; | ||
|
||
internal class AutoCloseOnReadCompleteStream : Stream | ||
{ | ||
internal class AutoCloseOnReadCompleteStream : Stream | ||
private readonly Stream _baseStream; | ||
|
||
public AutoCloseOnReadCompleteStream(Stream baseStream) | ||
{ | ||
private readonly Stream _baseStream; | ||
_baseStream = baseStream; | ||
} | ||
|
||
public AutoCloseOnReadCompleteStream(Stream baseStream) | ||
{ | ||
_baseStream = baseStream; | ||
} | ||
public override bool CanRead => _baseStream.CanRead; | ||
|
||
public override bool CanRead => _baseStream.CanRead; | ||
public override bool CanSeek => _baseStream.CanSeek; | ||
|
||
public override bool CanSeek => _baseStream.CanSeek; | ||
public override bool CanWrite => _baseStream.CanWrite; | ||
|
||
public override bool CanWrite => _baseStream.CanWrite; | ||
public override long Length => _baseStream.Length; | ||
|
||
public override long Length => _baseStream.Length; | ||
public override long Position { get => _baseStream.Position; set => _baseStream.Position = value; } | ||
|
||
public override long Position { get => _baseStream.Position; set => _baseStream.Position = value; } | ||
public override void Flush() | ||
{ | ||
_baseStream.Flush(); | ||
} | ||
|
||
public override void Flush() => _baseStream.Flush(); | ||
public override int Read(byte[] buffer, int offset, int count) | ||
{ | ||
var bytesRead = _baseStream.Read(buffer, offset, count); | ||
|
||
public override int Read(byte[] buffer, int offset, int 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) | ||
{ | ||
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; | ||
_baseStream.Close(); | ||
} | ||
|
||
public override long Seek(long offset, SeekOrigin origin) => _baseStream.Seek(offset, origin); | ||
return bytesRead; | ||
} | ||
|
||
public override long Seek(long offset, SeekOrigin origin) | ||
{ | ||
return _baseStream.Seek(offset, origin); | ||
} | ||
|
||
public override void SetLength(long value) => _baseStream.SetLength(value); | ||
public override void SetLength(long value) | ||
{ | ||
_baseStream.SetLength(value); | ||
} | ||
|
||
public override void Write(byte[] buffer, int offset, int count) => _baseStream.Write(buffer, offset, count); | ||
public override void Write(byte[] buffer, int offset, int count) | ||
{ | ||
_baseStream.Write(buffer, offset, count); | ||
} | ||
} |
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
Oops, something went wrong.