WICG / file-system-access

Expose the file system on the user’s device, so Web apps can interoperate with the user’s native applications.
https://wicg.github.io/file-system-access/
Other
654 stars 65 forks source link

Why we can store a fileHandle in indexedDB, but can NOT store an array of fileHandles in indexedDB? #414

Closed xieyuheng closed 1 year ago

jimmywarting commented 1 year ago

Uhm, i don't think it should be a problem...

Basically everything that's structural clonable works. that includes array of file handles.

I just tried it out and it works OK

  // My itty tiny bitty IndexedDB KV storage
  var {default: kv} = await import('https://localwebcontainer.com/clientmyadmin/shared/kv.js')
  var root = await navigator.storage.getDirectory()
  var a = await root.getFileHandle('file1.txt', { create: true })
  var b = await root.getFileHandle('file2.txt', { create: true })
  await kv('put', [a, b], 'my-files')
  console.log(await kv('get', 'my-files'))
a-sully commented 1 year ago

Basically everything that's structural clonable works. that includes array of file handles.

👍

xieyuheng commented 1 year ago

Sorry about this misreport, the problem is about vue reactive and the use of Proxy.

jimmywarting commented 1 year ago

Bit of topic

I'm wrong about not being able to store anything that is structural clonable in IndexedDB with globalThis.structuredClone(x) uh? Dose anyone else happen to know of anything else that can be stored in IndexedDB that isn't structural cloneable with structuredClone

...Maybe some Crypto class or something?

I think i was right.

inexorabletash commented 1 year ago

@jimmywarting - values in IDB are by definition "any serializable object" which bottoms out at the same place as structuredClone(). Under the hood, IDB effectively does a structuredClone() when you put a record, and another structuredClone() when you get a record. (There's a little extra magic in between to handle key extraction/injection, but that's not relevant here.)