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
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…