2016-12-01 21:27:53 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
2018-02-06 00:17:03 +04:00
|
|
|
(* Copyright (c) 2014 - 2018. *)
|
2016-12-01 21:27:53 +04:00
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
2017-01-23 14:09:45 +04:00
|
|
|
open Error_monad
|
|
|
|
|
2016-12-01 21:27:53 +04:00
|
|
|
let to_root = function
|
|
|
|
| `O ctns -> `O ctns
|
|
|
|
| `A ctns -> `A ctns
|
|
|
|
| `Null -> `O []
|
|
|
|
| oth -> `A [ oth ]
|
|
|
|
|
|
|
|
let write_file file json =
|
|
|
|
let json = to_root json in
|
2017-01-23 14:09:45 +04:00
|
|
|
protect begin fun () ->
|
|
|
|
Lwt_io.with_file ~mode:Output file begin fun chan ->
|
2018-02-08 13:51:01 +04:00
|
|
|
let str = Data_encoding.Json.to_string ~minify:false json in
|
2017-01-23 14:09:45 +04:00
|
|
|
Lwt_io.write chan str >>= fun _ ->
|
|
|
|
return ()
|
|
|
|
end
|
|
|
|
end
|
2016-12-01 21:27:53 +04:00
|
|
|
|
|
|
|
let read_file file =
|
2017-01-23 14:09:45 +04:00
|
|
|
protect begin fun () ->
|
|
|
|
Lwt_io.with_file ~mode:Input file begin fun chan ->
|
|
|
|
Lwt_io.read chan >>= fun str ->
|
|
|
|
return (Ezjsonm.from_string str :> Data_encoding.json)
|
|
|
|
end
|
|
|
|
end
|