Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
504 views
in Technique[技术] by (71.8m points)

javascript - Blazor WASM应用程序在加载目录时内存不足(Blazor WASM app running out of memory when loading directory)

I am very new to blazor and I am making a simple app for processing TDT files.

(我是blazor的新手,我正在制作一个用于处理TDT文件的简单应用程序。)

I have been using Tewr's file loader, but whenever I try to upload a 267 kilobyte directory it crashes saying it has run out of memory.

(我一直在使用Tewr的文件加载器,但是每当尝试上载267 KB的目录时,它都会崩溃,并指出它已用完内存。)

What am I doing wrong?

(我究竟做错了什么?)

Thanks in advance.

(提前致谢。)

@page "/sheetupload"
@using CurrieTechnologies.Razor.Clipboard
@inject ClipboardService clipboard
@using System.IO;
@inject IFileReaderService fileReaderService;

<h1>Hello, world!</h1>

<input type="file" @ref=fileRef multiple webkitdirectory/>
<button @onclick=ProcessFile>Read file</button>

@if (output != null)
{
<button @onclick="(async e => await clipboard.WriteTextAsync(output))">Copy To Clipboard</button>
<table>
    <tbody><pre>@output</pre></tbody>
</table>
}

@code {
ElementReference fileRef;

List<List<object>> sheet;

string output;

async Task ProcessFile()
{
    sheet = new List<List<object>>();
    var files = (await fileReaderService.CreateReference(fileRef).EnumerateFilesAsync()).ToList();
    foreach (IFileReference file in files)
    {
        using (Stream stream = await file.OpenReadAsync())
        {
            int size = (int)(await file.ReadFileInfoAsync()).Size;
            byte[] buffer = new byte[size];
            await stream.ReadAsync(buffer, 0, size);
            output = buffer.Length.ToString();

            string rawData = System.Text.Encoding.ASCII.GetString(buffer);

            List<object> currentRow = new List<object>();
            string currentCell = "";
            for (int i = 0; i < rawData.Length; i++)
            {
                if (rawData[i] == '')
                {
                    currentRow.Add(currentCell);
                }else if (rawData[i] == '
')
                {
                    currentRow.Add(currentCell);
                    sheet.Add(currentRow);
                }
                else
                {
                    currentCell += rawData[i];
                }
            }
        }
    }
  ask by user7323126 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...