mirror of
https://github.com/ldqk/Masuit.Tools.git
synced 2026-10-17 05:11:32 +08:00
Stream增加ToArrayAsync
This commit is contained in:
@@ -1,4 +1,11 @@
|
||||
using System.IO;
|
||||
#if NET5_0
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endif
|
||||
|
||||
namespace Masuit.Tools
|
||||
{
|
||||
@@ -30,5 +37,21 @@ namespace Masuit.Tools
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
#if NET5_0
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="stream"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<byte[]> ToArrayAsync(this Stream stream, CancellationToken cancellationToken = default)
|
||||
{
|
||||
byte[] bytes = new byte[stream.Length];
|
||||
await stream.ReadAsync(bytes, cancellationToken);
|
||||
stream.Seek(0, SeekOrigin.Begin);// 设置当前流的位置为流的开始
|
||||
return bytes;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
<LangVersion>9.0</LangVersion>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<CodeAnalysisRuleSet />
|
||||
<Version>2.4.1.2</Version>
|
||||
<Version>2.4.1.3</Version>
|
||||
<Authors>懒得勤快</Authors>
|
||||
<Description>Masuit.Tools基础公共库</Description>
|
||||
<Copyright>懒得勤快,长空X</Copyright>
|
||||
@@ -20,9 +20,9 @@
|
||||
<RepositoryType>Github</RepositoryType>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
|
||||
<FileVersion>2.4.1.2</FileVersion>
|
||||
<FileVersion>2.4.1.3</FileVersion>
|
||||
<Company>masuit.com</Company>
|
||||
<AssemblyVersion>2.4.1.2</AssemblyVersion>
|
||||
<AssemblyVersion>2.4.1.3</AssemblyVersion>
|
||||
<PackageLicenseUrl>https://github.com/ldqk/Masuit.Tools/blob/master/LICENSE</PackageLicenseUrl>
|
||||
<EmbedUntrackedSources>true</EmbedUntrackedSources>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
@@ -46,7 +46,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DnsClient" Version="1.3.2" />
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.11.29" />
|
||||
<PackageReference Include="HtmlSanitizer" Version="5.0.355" />
|
||||
<PackageReference Include="HtmlSanitizer" Version="5.0.372" />
|
||||
<PackageReference Include="Microsoft.Win32.Registry" Version="4.7.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
|
||||
|
||||
@@ -4,8 +4,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;netstandard2.1;net5</TargetFrameworks>
|
||||
<Description>
|
||||
包含一些常用的操作类,大都是静态类,加密解密,反射操作,硬件信息,字符串扩展方法,日期时间扩展操作,大文件拷贝,图像裁剪,html处理,验证码、NoSql等常用封装。
|
||||
<Description> 包含一些常用的操作类,大都是静态类,加密解密,反射操作,硬件信息,字符串扩展方法,日期时间扩展操作,大文件拷贝,图像裁剪,html处理,验证码、NoSql等常用封装。
|
||||
官网教程:https://masuit.com/55
|
||||
github:https://github.com/ldqk/Masuit.Tools
|
||||
</Description>
|
||||
@@ -21,10 +20,10 @@
|
||||
<UserSecretsId>830c282f-f7c1-42be-8651-4cd06ac8e73f</UserSecretsId>
|
||||
<RepositoryType>Github</RepositoryType>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
<Version>2.4.1.2</Version>
|
||||
<FileVersion>2.4.1.2</FileVersion>
|
||||
<Version>2.4.1.3</Version>
|
||||
<FileVersion>2.4.1.3</FileVersion>
|
||||
<Company>masuit.com</Company>
|
||||
<AssemblyVersion>2.4.1.2</AssemblyVersion>
|
||||
<AssemblyVersion>2.4.1.3</AssemblyVersion>
|
||||
<Authors>懒得勤快X</Authors>
|
||||
<RepositoryUrl>https://github.com/ldqk/Masuit.Tools</RepositoryUrl>
|
||||
<EmbedUntrackedSources>true</EmbedUntrackedSources>
|
||||
@@ -354,7 +353,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DnsClient" Version="1.3.2" />
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.11.29" />
|
||||
<PackageReference Include="HtmlSanitizer" Version="5.0.355" />
|
||||
<PackageReference Include="HtmlSanitizer" Version="5.0.372" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http" Version="5.0" />
|
||||
|
||||
@@ -402,7 +402,7 @@
|
||||
<Version>1.11.29</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="HtmlSanitizer">
|
||||
<Version>5.0.355</Version>
|
||||
<Version>5.0.372</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.AspNet.Mvc">
|
||||
<Version>5.2.7</Version>
|
||||
|
||||
Binary file not shown.
@@ -4,7 +4,7 @@
|
||||
<!--*-->
|
||||
<id>Masuit.Tools.Net</id>
|
||||
<!--*-->
|
||||
<version>2.4.1.2</version>
|
||||
<version>2.4.1.3</version>
|
||||
<title>Masuit.Tools</title>
|
||||
<!--*-->
|
||||
<authors>masuit.com</authors>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<RunAnalyzersDuringBuild>false</RunAnalyzersDuringBuild>
|
||||
<RunAnalyzersDuringLiveAnalysis>false</RunAnalyzersDuringLiveAnalysis>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Masuit.Tools.Core.Models;
|
||||
using Masuit.Tools;
|
||||
using Masuit.Tools.Core.Models;
|
||||
using Masuit.Tools.Reflection;
|
||||
using Masuit.Tools.Security;
|
||||
using Microsoft.AspNetCore;
|
||||
@@ -6,6 +7,7 @@ using Microsoft.AspNetCore.Hosting;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
|
||||
namespace NetCoreTest
|
||||
{
|
||||
@@ -13,6 +15,10 @@ namespace NetCoreTest
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var fs = File.OpenRead(@"E:\下载\BlazorSamples.7z");
|
||||
var bytes = fs.ToArrayAsync().Result;
|
||||
Console.WriteLine(bytes.Length);
|
||||
Console.ReadKey();
|
||||
var myClass = new MyClass()
|
||||
{
|
||||
MyProperty1 = 1,
|
||||
|
||||
Reference in New Issue
Block a user