Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add information about encoding/be explicit about encoding #269

Closed
Tracked by #501
matheus23 opened this issue Jul 22, 2021 · 2 comments
Closed
Tracked by #501

Add information about encoding/be explicit about encoding #269

matheus23 opened this issue Jul 22, 2021 · 2 comments

Comments

@matheus23
Copy link
Contributor

matheus23 commented Jul 22, 2021

Summary

Don't handle encoding in webnative very well. What is the data you can put into webnative? Are they utf8-encoded strings? Arrays of numbers? Uint8Arrays? And what do we get when we take it back out?

We need to get more explicit about this. This will also help us fix inconsistencies between the public and private filesystem.

Problem

There are multiple problems:

  • In the public filesystem you don't get back what you put into the filesystem, which can be very confusing:
    await fs.write(publicPath, "asdf") // input: string
    await fs.read(publicPath) // output: Uint8Array
    In the private filesystem this works.
  • In the private filesystem, everything is encoded as cbor, which stores some metadata about what type you're storing. E.g. int, boolean, string, number, list or record of things. On the public side, everything is just bytes.

Impact

  • It's very confusing to users.
  • There's a small overhead to store data on the private filesystem
  • It's impossible to make precise types for the UnixFS interface
  • It's hard to get strings from the public filesystem

Solution

We should provide an api just like node's fs.writeFile(path, data, { encoding: X }).

@icidasset
Copy link
Contributor

Partially addressed in 0.35, only uses Uint8Arrays now.

@icidasset
Copy link
Contributor

Implemented in #500
Part of #501

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants