Comments (10)
public static async Task SaveToFileAsync(this Stream stream,string filename)
{
await using FileStream destination = new FileStream(filename, FileMode.Create, FileAccess.Write);
await new BufferedStream(stream, 1048576).CopyToAsync((Stream) destination);
}
测试了一下换成这种写法也不会报错
from masuit.tools.
能否提供一个完整的可独立运行可复现这个bug的demo,我测试是可以正常调用不报错的,这是我的demo代码:
ConsoleApp1.zip
from masuit.tools.
我写了几个测试用例也没能复现,我再尝试一下看看
from masuit.tools.
复现了,下面是测试用例:
using Flurl.Http;
using Masuit.Tools.Files;
using Xunit.Abstractions;
[Fact]
public async Task 测试BUG()
{
for (int i = 0; i < 5; i++)
{
var stream=await "https://api.tianditu.gov.cn/cdn/plugins/cesium/Cesium_ext_min.js"
.GetStreamAsync();
await stream.SaveFileAsync("test-err" + Guid.NewGuid().ToString());
}
}
用到的库:
- Masuit.Tools.Abstractions 2.6.7.4
- Flurl.Http 3.2.4
from masuit.tools.
修改版本测试用例通过:
[Fact]
public async Task 修复后()
{
for (int i = 0; i < 5; i++)
{
var stream=await "https://api.tianditu.gov.cn/cdn/plugins/cesium/Cesium_ext_min.js"
.GetStreamAsync();
// await stream.SaveFileAsync("test-err" + Guid.NewGuid().ToString());
await FixedSaveToFileAsync(stream, "test-err" + Guid.NewGuid().ToString());
}
}
static async Task FixedSaveToFileAsync(Stream stream,string filename)
{
await using FileStream destination = new FileStream(filename, FileMode.Create, FileAccess.Write);
await new BufferedStream(stream, 1048576).CopyToAsync((Stream) destination);
}
from masuit.tools.
这个是用法问题了,Http响应流不能直接拿来存文件流,需要先转MemoryStream再用
from masuit.tools.
这个是用法问题了,Http响应流不能直接拿来存文件流,需要先转MemoryStream再用
如果是这样的话,扩展方法的this应该用MemoryStream类型更好吧,不然stream的变量点一下之后就出来了这个扩展方法,很容易写出bug诶
from masuit.tools.
Stream体系本来就很混乱,各种各样的实现,但是又不能限定只能给MemoryStream做扩展,很多其他的流类型也是可以正常转储文件的
from masuit.tools.
遇到不能直接转储文件的Stream就借助MemoryStream中转一下咯
from masuit.tools.
遇到不能直接转储文件的Stream就借助MemoryStream中转一下咯
那也只能这样了 ...🤣
from masuit.tools.
Related Issues (20)
- 请求添加新功能:能否添加标志位枚举获取Description HOT 5
- 请求添加新功能:增加密码生成/弱密码检测功能 HOT 5
- [BUG] 检测mp4文件,会出现异常System.ArgumentOutOfRangeException: The Position must be within the length of the Stream: 2041547 (Parameter 'value') HOT 4
- 请求添加新功能:取掉EFcore5.0 依赖 HOT 1
- 请求添加新功能:AES 加解密 CBC模式 HOT 2
- 请求添加新功能:bcrypt加密 HOT 2
- 没带缓存??就普通的内存缓存 HOT 3
- RSA签名验证是怎么用的? HOT 1
- 请求添加新功能:希望增加公式计算 HOT 3
- FTP判断当前目录下指定的子目录是否存在,这个代码好像不太对劲。 HOT 2
- Microsoft.EntityFrameworkCore.Relational限定可以修改为>=6.0.10吗 HOT 1
- [BUG].net版的日志写入存在问题 HOT 3
- 没错,反对996 人人有责 HOT 1
- [BUG] ini配置文件操作,没有ini文件生成 HOT 2
- 请求添加新功能:建议增加一个IsNotNullOrEmpty HOT 1
- 请求添加新功能:MaskEmailConverter等目前实现还是基于Newtonjson,感觉可以考虑增加对System.Text.json的支持了。 HOT 1
- [BUG] Masuit.Tools.Systems.Text.Json.MaskEmailConverter的wirterjson中的value方法少了null判断,有为空数据下直接异常了。 HOT 1
- [BUG]ToChineseMoney负数不生效 HOT 2
- 请问是否支持获取证书序列号 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from masuit.tools.