Hello,
The following code works if I create a file first. The directory permissions are proper. And I also noticed there are two Eio_main.run
. I believe there should only be one. So I tried to pass env
by declaring it in the sig
but the type looks odd. So I am wondering now about how to pass env
around.
Am I using the pattern wrongly ?
module type WalWriter =
sig
val write : bytes -> unit
val read : unit->string
end
module WalWriter = struct
let write (data : bytes) =
let ( / ) = Eio.Path.( / ) in
Eio_main.run @@ fun env ->
let path = Eio.Stdenv.fs env in
let p = path / "/Users"/"anu"/"Documents"/"rays"/"Bitcask"/"bitcask"/"bitcask.log" in
Eio.Path.with_open_out ~append:true ~create:(`If_missing 0o600) p (fun f ->
try
let bytes_written =
Eio.Flow.single_write f [Cstruct.of_bytes
data]
in Printf.printf "%d bytes written" bytes_written
with
| ex -> traceln "%a" Eio.Exn.pp ex
)
let read ()=
let ( / ) = Eio.Path.( / ) in
Eio_main.run @@ fun env ->
let path = Eio.Stdenv.fs env in
let p = path / "/Users"/"anu"/"Documents"/"rays"/"Bitcask"/"bitcask"/"bitcask.log" in
let lines =
if (Sys.file_exists "/Users/anu/Documents/rays/Bitcask/bitcask/bitcask.log") then
Eio.Path.load p
else
raise Not_found
in lines
end
Update :
module type WalWriter =
sig
val write : bytes -> Eio_unix.Stdenv.base -> unit
val read : unit -> Eio_unix.Stdenv.base -> string
end
This compiles and I have removed the redundant Eio_main.run
Thanks.