小编Bra*_*tty的帖子

高效地从asp.net core发送文件

我有兴趣将一些代码移植到 ASP.NET Core,并想知道从 ASP.NET Core Web 服务发送文件(也称为“下载”文件)的最有效方法。

使用旧的 ASP.NET 代码,我使用的是 FileStream:

var content = new FileStream(
    myLocation,
    FileMode.Open, FileAccess.Read, FileShare.Read);

var result = new HttpResponseMessage(HttpStatusCode.OK)
{
    Content = new StreamContent(content)
};
Run Code Online (Sandbox Code Playgroud)

但是,我试图找到与 FreeBSD 的 sendfile() 等效的 .NET 并找到HttpResponse.TransmitFile。我认为这会更快?

我还担心该文件在访问用户之前必须从 Kestrel 跳到 IIS。有什么建议吗?

c# asp.net response.transmitfile asp.net-web-api asp.net-core

8
推荐指数
1
解决办法
7986
查看次数

为什么在 WebAssembly 中 ALLOW_MEMORY_GROWTH=1 失败而 TOTAL_MEMORY=512MB 成功?

我有一个图像处理 Wasm 项目,它将不同的二值化算法应用于给定的图像。当我运行其中一种算法时,会产生此错误:

Uncaught abort("Cannot enlarge memory arrays to size 17100800 bytes (OOM). Either
(1) compile with  -s TOTAL_MEMORY=X  with X higher than the current value 16777216,
(2) compile with  -s ALLOW_MEMORY_GROWTH=1  which allows increasing the size at runtime, or
(3) if you want malloc to return NULL (0)
instead of this abort, compile with  -s ABORTING_MALLOC=0 ") at Error
Run Code Online (Sandbox Code Playgroud)

编译后"-s ALLOW_MEMORY_GROWTH=1",该算法在Chrome中并没有出错,而是将图像变成了黑色。连续第二次运行出现此错误:

Uncaught RuntimeError: memory access out of bounds

第一次在 Edge 中运行时,42.17134.1.0我收到此错误:

SCRIPT5147: The ArrayBuffer is …

emscripten webassembly

7
推荐指数
1
解决办法
7124
查看次数