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

A File needs a pointer back to its FileSystemHandle #148

Closed
tomayac opened this issue Jan 22, 2020 · 5 comments
Closed

A File needs a pointer back to its FileSystemHandle #148

tomayac opened this issue Jan 22, 2020 · 5 comments

Comments

@tomayac
Copy link
Contributor

tomayac commented Jan 22, 2020

For the File resulting from a call to await fileHandle.getFile(), there's no way back to the FileSystemHandle, forcing library authors to store the handle somewhere. It would be nice if File had a readonly handle attribute that would allow for intuitive open-edit-save flows. I realize this is more of a File API issue, but since FileSystemHandle is spec'ed here, I start the discussion here.

@mkruisselbrink
Copy link
Contributor

mkruisselbrink commented Jan 22, 2020

I'm curious to understand more of what you're trying to do here. In general I wouldn't expect anybody to ever hold on to the File object long-term (or call getFile() pre-emptively). File objects are conceptually snapshots, every time you save to the file (or otherwise modify the file on disk) you'll have to call getFile() again to get a new valid File object.

@tomayac
Copy link
Contributor Author

tomayac commented Jan 23, 2020

Note that this is not about holding on to the File object itself, but indeed to store a reference to a File's FileSystemHandle so that eventually one can write back to it. Here's a deep link. The idea is to have the file opening code (with a fallback to <input type="file">) in one module, and as a common denominator return Files objects.

@jimmywarting
Copy link

jimmywarting commented Mar 3, 2020

Not sure this is necessary or not.
I don't think the intent is to save the File somewhere but instead save the FileSytemFileHandle

FileSytemFileHandle should keep track of the File not the other way around...?

But to tackle your senario I would maybe have used WeakMap to do what you need to do

const wm = new WeakMap()
const fileHandle = await chooseFileSystemEntries({ type:'openFile' })
const file = await fileHandle.getfile()
wm.set(file, fileHandle)

// later
fileHandle = wm.get(file)

// or simply just have an object: 
{ fileHandle, file }

(haven't played around much with native fs)

@tomayac
Copy link
Contributor Author

tomayac commented Mar 12, 2020

Thanks for the feedback. The situation will also improve once FileSystemHandle s can be stored.

@mkruisselbrink
Copy link
Contributor

mkruisselbrink commented Apr 9, 2020

Closing this issue. Nothing stops you from storing a FileSystemHandle on the File object yourself, so it doesn't seem like there would be much benefit in providing that automatically.

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

3 participants