Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 1969

Reading a file contents

$
0
0

I wonder if I missed something.

I was a bit bummed that I had to write all that to read the contents of a file (and figure out how as I could not find an example in the docs!):

type blob
@send external text: blob => string = "text"
@module("fs") external openFile: string => promise<blob> = "openAsBlob"

let load = async name => {
  let v = await openFile(name)
  v->text
}

I also feel like I am cheating a bit as the “text” function actually returns a promise, but thanks to Javascript promise flattening my “load” function works fine.

Is it really that hard to read a file in ReScript? Are there any plans for a standard “Fs” module?


Viewing all articles
Browse latest Browse all 1969

Trending Articles