-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 parent
cb5b6e4
commit 10f3b89
Showing
13 changed files
with
411 additions
and
11 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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// <copyright file="StreamExtensions.cs" company="Drastic Actions"> | ||
// Copyright (c) Drastic Actions. All rights reserved. | ||
// </copyright> | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace FishyFlip.Tools; | ||
|
||
/// <summary> | ||
/// Stream Extensions. | ||
/// </summary> | ||
public static class StreamExtensions | ||
{ | ||
#if NETSTANDARD | ||
/// <summary> | ||
/// Asynchronously reads exactly the specified number of bytes from the stream into the buffer. | ||
/// </summary> | ||
/// <param name="stream">The stream to read from.</param> | ||
/// <param name="buffer">The buffer to store the read bytes.</param> | ||
/// <param name="offset">The zero-based byte offset in the buffer at which to begin storing the data read from the stream.</param> | ||
/// <param name="count">The maximum number of bytes to read.</param> | ||
/// <returns>A task representing the asynchronous operation.</returns> | ||
public static async Task ReadExactlyAsync(this Stream stream, byte[] buffer, int offset, int count) | ||
{ | ||
int totalRead = 0; | ||
while (totalRead < count) | ||
{ | ||
int bytesRead = await stream.ReadAsync(buffer, offset + totalRead, count - totalRead); | ||
if (bytesRead == 0) | ||
{ | ||
throw new EndOfStreamException("End of stream reached before fulfilling read request."); | ||
} | ||
|
||
totalRead += bytesRead; | ||
} | ||
} | ||
#endif | ||
} |
Oops, something went wrong.