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

client.put API is ambiguous and confusing #533

Open
Gozala opened this issue Oct 13, 2021 · 3 comments
Open

client.put API is ambiguous and confusing #533

Gozala opened this issue Oct 13, 2021 · 3 comments
Labels
kind/enhancement A net-new feature or improvement to an existing feature need/go-nogo-decision stack/api-protocols

Comments

@Gozala
Copy link
Contributor

Gozala commented Oct 13, 2021

I find client.put API to be confusing and ambiguous. I suspect it inherits an unfortunate API design from ipfs, but I think we can do better.

Problem

wrapWithDirectory controls behavior of the method but in it is often not obvious what the result of it's behavior is, e.g. docs suggest following:

https://github.com/web3-storage/docs/blob/85cae31a077fe4325d5dc5149f918a9a6fda6ec5/docs/reference/client-library.md#L133-L146

However, if you do this instead:

const cid = await client.put(files, { wrapWithDirectory: false })

The contents of the files directory will be at the top level, instead of the files directory itself:

bafybeiebez7epbidb7f6fcurnd5ukpokrpq5wkrsuakynukpxxo4y4ewvi/
├── hello.txt
└── stuff
└── things.md

But even above example produces directory containing files. How can it not unless you provide just a single file ?

Proposal

I would suggest avoiding ambiguity simply by following nft.storage client API design that intentionally avoids ambiguity here and a control flag:

  1. storeBlob can stores single file. Note that it's intentionally storeBlob not storeFile because file name and mime type would be meaningless.
  2. storeDirectory stores a filesystem tree and as name suggests produces directory.

Note that this makes wrapWithDirectory obsolete, want to wrap just use:

storeDirectory([new File([content], `dir/${name}`))

Want just file without intermediary directory, easy

storeDirectory([new File([content]), 'file')
@Gozala Gozala added kind/enhancement A net-new feature or improvement to an existing feature need/triage Needs initial labeling and prioritization labels Oct 13, 2021
@Gozala
Copy link
Contributor Author

Gozala commented Oct 13, 2021

Alternative could be a companion library that allows you to build cars representing arbitrary directory structures with web compatible APIs

interface Lib {
  encode(handle:FileSystemHandle):Car
   // @see https://wicg.github.io/file-system-access/#filesystemfilehandle
  createFile():FileSystemFileHandle
  // @see https://wicg.github.io/file-system-access/#filesystemdirectoryhandle
  createDirectory():FileSystemDirectoryHandle
}

interface Car extends Blob {
  readonly type: 'application/car'
}

@atopal atopal removed the need/triage Needs initial labeling and prioritization label Oct 15, 2021
@vasco-santos
Copy link
Contributor

Note that this makes wrapWithDirectory obsolete, want to wrap just use:

I think this is something we will want! Even from unixfs: ipfs/js-ipfs-unixfs#176

@yusefnapora
Copy link
Contributor

I like this proposal - it feels a lot less surprising to have a separate method for storing "unwrapped" blobs.

@dchoi27 dchoi27 changed the title client.put API is ambigius and confusing client.put API is ambiguous and confusing Jan 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement A net-new feature or improvement to an existing feature need/go-nogo-decision stack/api-protocols
Projects
None yet
Development

No branches or pull requests

5 participants