diff --git a/src/Tiny_httpd_dir.ml b/src/Tiny_httpd_dir.ml index 91183660..94b63399 100644 --- a/src/Tiny_httpd_dir.ml +++ b/src/Tiny_httpd_dir.ml @@ -82,8 +82,8 @@ let vfs_of_dir (top:string) : vfs = let contains f = Sys.file_exists (top // f) let list_dir f = Sys.readdir (top // f) let read_file_content f = - let ic = open_in_bin (top // f) in - Tiny_httpd_stream.of_chan ic + let ic = Unix.(openfile (top // f) [O_RDONLY] 0) in + Tiny_httpd_stream.of_fd ic let create f = let oc = open_out_bin (top // f) in let write = output oc in @@ -398,4 +398,3 @@ module Embedded_fs = struct end in (module M) end - diff --git a/src/Tiny_httpd_stream.ml b/src/Tiny_httpd_stream.ml index 2b12ab02..9490e016 100644 --- a/src/Tiny_httpd_stream.ml +++ b/src/Tiny_httpd_stream.ml @@ -120,13 +120,13 @@ let of_string s : t = of_bytes (Bytes.unsafe_of_string s) let with_file ?buf_size file f = - let ic = open_in file in + let ic = Unix.(openfile file [O_RDONLY] 0) in try - let x = f (of_chan ?buf_size ic) in - close_in ic; + let x = f (of_fd ?buf_size ic) in + Unix.close ic; x with e -> - close_in_noerr ic; + Unix.close ic; raise e let read_all ?(buf=Buf.create()) (self:t) : string =