-
Notifications
You must be signed in to change notification settings - Fork 19
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
Support reading file metadata #12
Comments
You can't get the size without reading it in? What about getSize()? |
You're correct that One specific use case for last-modified time (mentioned in WICG/file-system-access#101) is watching file system changes. A specific API for this was requested here WICG/file-system-access#72 (with a lot of upvotes) and sketched out in this doc, though this also seems more relevant outside of OPFS and it's unclear whether that new API would apply to files within the OPFS. If that API does not apply to the OPFS (assuming its developed at all) then last-modified time is the only way to watch file system changes. This seems like reasonable metadata to provide? In general that I agree these metadata seem less useful in the OPFS than outside of it, but to me it seems there's enough reason to want these in the OPFS to support them eventually |
Within OPFS the only way a file can change is if another handle (AccessHandle, SyncAccessHandle, or WritableFileStream) or directory operation (proposed move()) were to modify it, either from the same worker, another worker or mainthread in the same tab, or from another tab on the same origin. We can ignore external modifications to an OPFS file, I believe. So I think the local cache issue seems a valid point in favor of lastModifiedAt() (or whatever). Are there good arguments for anything else? If we cared, we could have notifications on change for OPFS since we control the sources of such changes, but I don't think there is any significant usecase for this complexity. |
I found a round about way of getting last modified date out of directories... that just isn't possible with todays newest whatwg/fs api... I have just learned that The good old entry api by Blink have a getMetadata function. const webkitRoot = await new Promise(rs => {
try {
webkitRequestFileSystem(0, 0, x => rs(x.root), () => rs())
} catch (err) {rs() }
})
function getMetadata(absolutePath) {
return new Promise((rs, rj) => {
webkitRoot.getDirectory(absolutePath, {}, h => h.getMetadata(rs, rj), rj)
})
}
function getFileMetadata(absolutePath) {
return new Promise((rs, rj) => {
webkitRoot.getFile(absolutePath, {}, h => h.getMetadata(rs, rj), rj)
})
} For obvious reasons, you will not be able to get metadata out of user supplied directories/files from the picker. (it will only work with |
currently building a file explorer at the moment, and i wish to use metadata instead of |
With SyncAccessHandle, you can call getSize() without creating a blob or reading it into memory. If we added a lastModified(), that would cover some of what you want. MimeType... while we could add the concept of a MimeType to OPFS files (though this might require some type of DB use -- chrome and Firefox are already using one; not sure about Apple), underlying filesystems don't necessarily have the concept as part of their metadata. I would lean against such a proposal. |
Browser seems to have something like this built in: https://mimesniff.spec.whatwg.org ? |
Let's keep this issue scoped to metadata that is typically exposed across various file systems. (It seems reasonable to file an issue to consider exposing sniffing, but that's a fair bit of work and given that we don't necessarily want to extend it beyond what we need for the web it's unclear if that's a good pattern here.) |
Would extended attributes also be something we could consider potentially in scope for this issue? Or should that be a separate issue for discussion |
Migrated from WICG/file-system-access#101 (see #2)
We should at least support the last-modified time and size, though we could consider other information such as the creation time.
For a file, it's currently not possible to get the size without reading in the file into memory via
getFile()
.For a directory, it's currently not possible to get the number of files in the directory without iterating through it (requested in WICG/file-system-access#215).
The text was updated successfully, but these errors were encountered: