juancarlospaco / nodejs

Alternative StdLib for Nim for NodeJS/JavaScript targets, hijacks NodeJS StdLib for Nim
https://juancarlospaco.github.io/nodejs
MIT License
205 stars 52 forks source link

TypeError: c_1455079.charCodeAt is not a function" on jsfs' readFileSync #1

Closed halloleo closed 3 years ago

halloleo commented 3 years ago

I'm trying nodejs/jsfs and get a node runtime error "TypeError: c_1455079.charCodeAt is not a function".

Here my little program read_try.nim:

import nodejs/jsfs

requireFs()
let data = readFileSync("sometext.txt")
echo $data

and I compile it with

nim js read_try.nim

Does this maybe means, node cannot find the file sometext.txt? But sounds weird to me.

juancarlospaco commented 3 years ago

Yes, is a Bug.

We need more testers, if you can test as much as you can of the functions and report the bugs would be cool.

Node documentation does not mention any type at all, that makes hard to determine the return types and argument types.

halloleo commented 3 years ago

Thanks @juancarlospaco for the super-prompt fix! I updated to HEAD and it works perfectly. :smile:

We need more testers, if you can test as much as you can of the functions and report the bugs would be cool.

I certainly will test other functions in your package.

Node documentation does not mention any type at all, that makes hard to determine the return types and argument types.

Well, JavaScript is not TypeScript...

juancarlospaco commented 3 years ago

I certainly will test other functions in your package.

So you get to test other stuff?, it worked in the end?. :slightly_smiling_face:

halloleo commented 3 years ago

Just coming back to this: Yes, it worked at the end:

For purely text files your fix does the job perfectly. With binary data however I had trouble using the toString conversion when passing the content further to another JavaScriptmodule.

I'm now reading the file as an ArrayBuffer and use then for text content an explicit converter function like this:

func arraybuffer2cstring(buf: cstring): cstring {.importjs: """
  new TextDecoder("utf-8").decode(#)
""".}
  ## Convert an ArrayBuffer to a JS String
juancarlospaco commented 3 years ago

https://github.com/juancarlospaco/nodejs/commit/62c6451b82e33f67573ae4236c6f2036f90bbe78 🙂