mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
Switch loading file chunks to list of bytes instead of string
This commit is contained in:
parent
3943ff9ffd
commit
75eccf5bac
4 changed files with 5 additions and 6 deletions
|
@ -82,8 +82,7 @@ getCharScope = \scope ->
|
||||||
Err OutOfBounds ->
|
Err OutOfBounds ->
|
||||||
when scope.data is
|
when scope.data is
|
||||||
Some h ->
|
Some h ->
|
||||||
chunk <- Task.await (File.chunk h)
|
bytes <- Task.await (File.chunk h)
|
||||||
bytes = Str.toUtf8 chunk
|
|
||||||
when List.first bytes is
|
when List.first bytes is
|
||||||
Ok val ->
|
Ok val ->
|
||||||
# This starts at 1 because the first charater is already being returned.
|
# This starts at 1 because the first charater is already being returned.
|
||||||
|
|
|
@ -7,7 +7,7 @@ Handle: [ @Handle U64 ]
|
||||||
line : Handle -> Task.Task Str *
|
line : Handle -> Task.Task Str *
|
||||||
line = \@Handle handle -> Effect.after (Effect.getFileLine handle) Task.succeed
|
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
|
chunk = \@Handle handle -> Effect.after (Effect.getFileBytes handle) Task.succeed
|
||||||
|
|
||||||
open : Str -> Task.Task Handle *
|
open : Str -> Task.Task Handle *
|
||||||
|
|
|
@ -10,7 +10,7 @@ platform examples/cli
|
||||||
closeFile : U64 -> Effect {},
|
closeFile : U64 -> Effect {},
|
||||||
withFileOpen : Str, (U64 -> Effect (Result ok err)) -> Effect {},
|
withFileOpen : Str, (U64 -> Effect (Result ok err)) -> Effect {},
|
||||||
getFileLine : U64 -> Effect Str,
|
getFileLine : U64 -> Effect Str,
|
||||||
getFileBytes : U64 -> Effect Str,
|
getFileBytes : U64 -> Effect (List U8),
|
||||||
putLine : Str -> Effect {},
|
putLine : Str -> Effect {},
|
||||||
putRaw : Str -> Effect {},
|
putRaw : Str -> Effect {},
|
||||||
# Is there a limit to the number of effect, uncomment the next line and it crashes
|
# Is there a limit to the number of effect, uncomment the next line and it crashes
|
||||||
|
|
|
@ -171,7 +171,7 @@ pub fn roc_fx_getFileLine(br_ptr: *mut BufReader<File>) -> RocStr {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[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 br = unsafe { &mut *br_ptr };
|
||||||
let mut buffer = [0; 0x10 /* This is intentially small to ensure correct implementation */];
|
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[..])
|
.read(&mut buffer[..])
|
||||||
.expect("Failed to read bytes from file");
|
.expect("Failed to read bytes from file");
|
||||||
|
|
||||||
RocStr::from_slice(&buffer[..count])
|
RocList::from_slice(&buffer[..count])
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue