-
Notifications
You must be signed in to change notification settings - Fork 134
fix!: require path in addFile call #754
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
Conversation
If the user passes a `FileCandidate` with a `path` property or passes
the `wrapWithDirectoryOption` the return type of `fs.addFile` will
be a `DirectoryEntry`.
This breaks existing behaviour where it will always be a `FileEntry`
Since `URLSource` returns a `{ content, path }` candidatem this can
cause a `DirectoryEntry` to be returned whereas it used to always be
a `FileEntry`. An `ignorePath` option has been added to restore the
previous behavior.
Fixes #707
BREAKING CHANGE: addFile can sometimes return a directory, URLSource returns directory when a path is present
|
cc @2color - the other option here is to return a E.g. As implemented it is: |
|
I'm pretty confused about the role and interplay between IIUC, However, if you only pass I added the following test (locally), but I don't understand why only passing and
In the last example, do you mean Either way, that seems to make sense. If you pass either path or directory, you should expect to get back a directory. |
|
The directory containing a raw entry without a path being empty seems to be a bug in the importer.
That said I’d really like the output type to be consistent. Maybe we also make If the user just wants to add file contents without metadata (file name, mode/mtime/etc) they can use |
I can't really comment on it, since I am not sure I fully understood how it's meant to be used. From my understanding,
Seems sensible. |
The intended use-case is reflected in this test. That said, I'm not sure why we couldn't require use of something like: await addAll([{
path: '/foo.txt',
content: Uint8Array.from([0, 1, 2, 3])
}, {
path: '/bar.txt',
content: Uint8Array.from([0, 1, 2, 3])
}])instead of: await addAll([{
path: 'foo.txt',
content: Uint8Array.from([0, 1, 2, 3])
}, {
path: 'bar.txt',
content: Uint8Array.from([0, 1, 2, 3])
}], {
wrapWithDirectory: true
})Either way, I think |
|
Done in #758 |
Switch away from `addFile` as it will require paths after #754
Switch away from `addFile` as it will require paths after #754
|
After reading the conversation here, I feel awkward about could we be even more explicit and just create a |
That's a fair point. It's worth pointing out that w3storage/storacha learned from user feedback and wrap by default to ensure filename is retained. Either way, we already have |
2color
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
Any blockers @achingbrain? |
Actually, I can't get |
|
Here's something that's confusing about the current This will return a directory with the filename retained. const helia = await createHeliaHTTP()
const ufs = unixfs(helia)
// add a file and wrap in a directory
const readmeCid = await fs.addFile({
path: './huge-file.html'
})However, any other combination using a bytestream (even including const helia = await createHeliaHTTP()
// create a filesystem on top of Helia, in this case it's UnixFS
const ufs = unixfs(helia)
const readmeCid = await ufs.addFile({
content: fs.createReadStream('./huge-file.html'),
path: './huge-file.html'
}, {
wrapWithDirectory: true
}) // RETURNS fileconst readmeCid = await ufs.addFile({
content: fs.createReadStream('./huge-file.html'),
path: './huge-file.html'
}) // RETURNS file |
reproduced all of the above today, with a fresh build (by accident) |
|
Thanks for the input all, you can try out the changes here ahead of final release (see #766) with |
|
using
(the CID changes, tho, depending on the wrapWithDirectory flag, so it IS being passed and affecting the contents of that root UnixFS CID, but none of the |
To ensure metadata is always stored, the CID returned from
addFilewill resolve to a directory.The
pathproperty is now required of the import candidate passed toaddFile, if it's not necessary to store a path as part of a file, useaddBytesoraddByteStream.Since
urlSourcereturns a{ content, path }candidate, it can be used withaddFile.To import directly from a URL without a path, a
urlByteStreamfunction has been added for use withaddByteStream.Fixes #707
BREAKING CHANGE: addFile requires the import candidate to have a
pathproperty and the returned CID will always resolve to a directoryChange checklist