Skip to content

Commit f81f2d0

Browse files
authored
Runtime: fix caml_read_file_content (#1366)
1 parent 1ecf836 commit f81f2d0

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# dev (202?-??-??) - ??
2+
## Features/Changes
3+
4+
## Bug fixes
5+
Runtime: fix caml_read_file_content
6+
17
# 5.0.0 (2022-12-20) - Lille
28
## Features/Changes
39
* Compiler: add support for effect handlers (--enable=effects)

lib/tests/test_sys.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,13 @@ let%expect_test _ =
101101
print_digest (Digest.channel c size);
102102
[%expect {| 573705548ab0d6c8a2193579611511a2 |}];
103103
()
104+
105+
let%expect_test _ =
106+
print_digest (Digest.string content);
107+
[%expect {| dd5da7fa373a2b2257d361aaf76845a0 |}];
108+
let c = open_out_bin "/static/temp0" in
109+
output_string c content;
110+
close_out c;
111+
let content' = Sys_js.read_file ~name:"/static/temp0" in
112+
assert (content' = content);
113+
[%expect {||}]

runtime/fs.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,17 +322,17 @@ function jsoo_create_file(name,content) {
322322

323323

324324
//Provides: caml_read_file_content
325-
//Requires: resolve_fs_device, caml_raise_no_such_file, caml_create_bytes, caml_string_of_bytes
325+
//Requires: resolve_fs_device, caml_raise_no_such_file, caml_string_of_array
326326
//Requires: caml_string_of_jsbytes, caml_jsbytes_of_string
327327
function caml_read_file_content (name) {
328328
var name = (typeof name == "string")?caml_string_of_jsbytes(name):name;
329329
var root = resolve_fs_device(name);
330330
if(root.device.exists(root.rest)) {
331331
var file = root.device.open(root.rest,{rdonly:1});
332332
var len = file.length();
333-
var buf = caml_create_bytes(len);
333+
var buf = new Uint8Array(len);
334334
file.read(0,buf,0,len);
335-
return caml_string_of_bytes(buf)
335+
return caml_string_of_array(buf)
336336
}
337337
caml_raise_no_such_file(caml_jsbytes_of_string(name));
338338
}

0 commit comments

Comments
 (0)