1
0
Fork 0
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:
Brian Fiete 2023-01-26 10:56:05 -05:00
parent 998cdfae4c
commit 701d28d2d6

View file

@ -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)