File tree Expand file tree Collapse file tree 2 files changed +27
-27
lines changed
Expand file tree Collapse file tree 2 files changed +27
-27
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ // Normally `open NodeJs` would be used to shorten the module accessors
2+ // this is not done in the example to make it clear where things come from
3+
4+ let data = "Sample text to write to a file!" -> NodeJs .Buffer .fromString
5+ let process = NodeJs .Process .process
6+
7+ let outputPath = NodeJs .Path .relative (~from = NodeJs .Process .cwd (process ), ~to_ = "example__output.txt" )
8+
9+ let writeStream = NodeJs .Fs .createWriteStream (outputPath )
10+
11+ let logErrorIfExists = maybeError =>
12+ switch Js .Nullable .toOption (maybeError ) {
13+ | Some (err ) => Js .log2 ("An error occurred" , err )
14+ | None => ()
15+ }
16+
17+ let () =
18+ writeStream
19+ -> NodeJs .Stream .writeWith (
20+ data ,
21+ ~callback = maybeError => {
22+ logErrorIfExists (maybeError )
23+ Js .log ("Finished" )
24+ },
25+ (),
26+ )
27+ -> ignore
You can’t perform that action at this time.
0 commit comments