Switch loading file chunks to list of bytes instead of string

This commit is contained in:
Brendan Hansknecht 2021-10-03 14:56:09 -07:00
parent 3943ff9ffd
commit 75eccf5bac
4 changed files with 5 additions and 6 deletions

View file

@ -82,8 +82,7 @@ getCharScope = \scope ->
Err OutOfBounds ->
when scope.data is
Some h ->
chunk <- Task.await (File.chunk h)
bytes = Str.toUtf8 chunk
bytes <- Task.await (File.chunk h)
when List.first bytes is
Ok val ->
# This starts at 1 because the first charater is already being returned.

View file

@ -7,7 +7,7 @@ Handle: [ @Handle U64 ]
line : Handle -> Task.Task Str *
line = \@Handle handle -> Effect.after (Effect.getFileLine handle) Task.succeed
chunk : Handle -> Task.Task Str *
chunk : Handle -> Task.Task (List U8) *
chunk = \@Handle handle -> Effect.after (Effect.getFileBytes handle) Task.succeed
open : Str -> Task.Task Handle *

View file

@ -10,7 +10,7 @@ platform examples/cli
closeFile : U64 -> Effect {},
withFileOpen : Str, (U64 -> Effect (Result ok err)) -> Effect {},
getFileLine : U64 -> Effect Str,
getFileBytes : U64 -> Effect Str,
getFileBytes : U64 -> Effect (List U8),
putLine : Str -> Effect {},
putRaw : Str -> Effect {},
# Is there a limit to the number of effect, uncomment the next line and it crashes

View file

@ -171,7 +171,7 @@ pub fn roc_fx_getFileLine(br_ptr: *mut BufReader<File>) -> RocStr {
}
#[no_mangle]
pub fn roc_fx_getFileBytes(br_ptr: *mut BufReader<File>) -> RocStr {
pub fn roc_fx_getFileBytes(br_ptr: *mut BufReader<File>) -> RocList<u8> {
let br = unsafe { &mut *br_ptr };
let mut buffer = [0; 0x10 /* This is intentially small to ensure correct implementation */];
@ -179,7 +179,7 @@ pub fn roc_fx_getFileBytes(br_ptr: *mut BufReader<File>) -> RocStr {
.read(&mut buffer[..])
.expect("Failed to read bytes from file");
RocStr::from_slice(&buffer[..count])
RocList::from_slice(&buffer[..count])
}
#[no_mangle]