mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-20 08:58:00 +02:00
Faster File.ReadAll
This commit is contained in:
parent
998cdfae4c
commit
701d28d2d6
1 changed files with 6 additions and 3 deletions
|
@ -30,15 +30,18 @@ namespace System.IO
|
||||||
{
|
{
|
||||||
public static Result<void, FileError> ReadAll(StringView path, List<uint8> outData)
|
public static Result<void, FileError> ReadAll(StringView path, List<uint8> outData)
|
||||||
{
|
{
|
||||||
FileStream fs = scope FileStream();
|
UnbufferedFileStream fs = scope UnbufferedFileStream();
|
||||||
var result = fs.Open(path, .Open, .Read, .ReadWrite);
|
var result = fs.Open(path, .Open, .Read, .ReadWrite);
|
||||||
if (result case .Err(let err))
|
if (result case .Err(let err))
|
||||||
return .Err(.OpenError(err));
|
return .Err(.OpenError(err));
|
||||||
|
|
||||||
|
int64 fileSize = fs.Length;
|
||||||
|
outData.Reserve(fileSize);
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
uint8[4096] buffer;
|
uint8[8192] buffer;
|
||||||
switch (fs.TryRead(.(&buffer, 4096)))
|
switch (fs.TryRead(.(&buffer, 8192)))
|
||||||
{
|
{
|
||||||
case .Ok(let bytes):
|
case .Ok(let bytes):
|
||||||
if (bytes == 0)
|
if (bytes == 0)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue