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

Proposal: less generic / confusing interface #98

Open
Gozala opened this issue Oct 19, 2021 · 0 comments
Open

Proposal: less generic / confusing interface #98

Gozala opened this issue Oct 19, 2021 · 0 comments

Comments

@Gozala
Copy link

Gozala commented Oct 19, 2021

I find myself staring going back to docs / examples to try and figure out what various options would do to make sure I get things right. In my experience this is an opportunity to improve API such that it is difficult to misuse / misinterpret.

Given a bit of experience here are few suggestions:

  1. Expose separate APIs per use case:

    • pack a file - Most cases I've encountered so far it's a single file in which case following options are confusing and serve little purpose
      1. multiple inputs
      2. path of the input
      3. wrapWithDirectory
    • pack a directory of files - This could also be simplified by
      1. Getting rid of wrapWithDirectory option (if you want to warp file with dir use packDiretory and pass a single file.
  2. Let user normalize input instead

    I think this is idiosyncrasy of IPFS that is really not worth replicating. Input type is extremely complex which is flexible enough to take almost anything yet it is not always obvious how each one is treated.

    I think API can be a lot nicer if it let user deal with input normalization and was itself was super simple

    • packFile({ content: Blob, ... })
    • packDirectory({ files: File[], ... })

    Files and Blobs can easily be created from all those input types and bad inputs.

  3. Allow deciding what output should be afterwards

    Right now you have to pick between blob, fs and stream packer. I would suggest instead having single result value Pack that is:

    interface WebPack extends Blob {
        type: 'File' | 'Directory'
        readonly maxChunkSize: number
        readonly blockstore: BlockStore
    }

    And following in node:

    interface NodePack extends WebPack {
       // mimics https://nodejs.org/dist/latest-v17.x/docs/api/fs.html#fswritefilefile-data-options-callback
       writeFile(path:string, options:import('fs').WriteFileOptions):Promise<void>
       // mimics https://nodejs.org/dist/latest-v17.x/docs/api/fs.html#fscreatereadstreampath-options
       createReadStream():import('stream').Readable
    }

    Also given that web streams and blobs are coming to node, I'm not sure if it's even worth doing node specific things.

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

No branches or pull requests

2 participants