diff --git a/CHANGES.md b/CHANGES.md index 1401622ebe..abc1d18e38 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,9 @@ +# dev (202?-??-??) - ?? +## Features/Changes + +## Bug fixes +Runtime: fix caml_read_file_content + # 5.0.0 (2022-12-20) - Lille ## Features/Changes * Compiler: add support for effect handlers (--enable=effects) diff --git a/lib/tests/test_sys.ml b/lib/tests/test_sys.ml index ad9adc3744..07607be86b 100644 --- a/lib/tests/test_sys.ml +++ b/lib/tests/test_sys.ml @@ -101,3 +101,13 @@ let%expect_test _ = print_digest (Digest.channel c size); [%expect {| 573705548ab0d6c8a2193579611511a2 |}]; () + +let%expect_test _ = + print_digest (Digest.string content); + [%expect {| dd5da7fa373a2b2257d361aaf76845a0 |}]; + let c = open_out_bin "/static/temp0" in + output_string c content; + close_out c; + let content' = Sys_js.read_file ~name:"/static/temp0" in + assert (content' = content); + [%expect {||}] diff --git a/runtime/fs.js b/runtime/fs.js index aa4968721d..58b272755a 100644 --- a/runtime/fs.js +++ b/runtime/fs.js @@ -322,7 +322,7 @@ function jsoo_create_file(name,content) { //Provides: caml_read_file_content -//Requires: resolve_fs_device, caml_raise_no_such_file, caml_create_bytes, caml_string_of_bytes +//Requires: resolve_fs_device, caml_raise_no_such_file, caml_string_of_array //Requires: caml_string_of_jsbytes, caml_jsbytes_of_string function caml_read_file_content (name) { var name = (typeof name == "string")?caml_string_of_jsbytes(name):name; @@ -330,9 +330,9 @@ function caml_read_file_content (name) { if(root.device.exists(root.rest)) { var file = root.device.open(root.rest,{rdonly:1}); var len = file.length(); - var buf = caml_create_bytes(len); + var buf = new Uint8Array(len); file.read(0,buf,0,len); - return caml_string_of_bytes(buf) + return caml_string_of_array(buf) } caml_raise_no_such_file(caml_jsbytes_of_string(name)); }