-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into production
- Loading branch information
Showing
3 changed files
with
629 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.IO; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SageTools.Extension | ||
{ | ||
public static partial class Extension | ||
{ | ||
/// <summary> | ||
/// 将流读为字符串 | ||
/// 注:默认使用UTF-8编码 | ||
/// </summary> | ||
/// <param name="stream">流</param> | ||
/// <param name="encoding">指定编码</param> | ||
/// <returns></returns> | ||
public static async Task<string> ReadToStringAsync(this Stream stream, Encoding encoding = null) | ||
{ | ||
encoding ??= Encoding.UTF8; | ||
|
||
if (stream.CanSeek) | ||
{ | ||
stream.Seek(0, SeekOrigin.Begin); | ||
} | ||
|
||
var resStr = await new StreamReader(stream, encoding).ReadToEndAsync(); | ||
|
||
if (stream.CanSeek) | ||
{ | ||
stream.Seek(0, SeekOrigin.Begin); | ||
} | ||
|
||
return resStr; | ||
} | ||
} | ||
} |
Oops, something went wrong.