WICG / storage-foundation-api-explainer

Explainer showcasing a new web storage API, NativeIO
Apache License 2.0
63 stars 8 forks source link

`storageFoundation.getRemainingCapacity()` unaware of previously created files #26

Open tomayac opened 3 years ago

tomayac commented 3 years ago

This may well be working as intended, but it is confusing to me. Files are persisted across reloads and consume storage. When I request capacity, the existing files are not subtracted from that. On the other hand, when I delete a previously created file, I can magically create storage capacity that I haven't requested.

Description of the steps

  1. Request 100 bytes of storage.
  2. Create a file with a length of 100 bytes.
  3. Run storageFoundation.getRemainingCapacity() and note it's 0.
  4. Reload and observe the file is still there.
  5. Request 50 bytes of storage.
  6. Delete the previously created file.
  7. Run storageFoundation.getRemainingCapacity() and note it's 150.

Here's the code:

await storageFoundation.requestCapacity(100)
// 100
await storageFoundation.getAll()
// []
let file = await storageFoundation.open('foo')
// undefined
await file.setLength(100)
// undefined
await storageFoundation.getRemainingCapacity()
// 0

/* 🔄 Reload */

await storageFoundation.getRemainingCapacity()
// 0
await storageFoundation.getAll()
// ["foo"]
await storageFoundation.delete('foo')
//undefined
await storageFoundation.getAll()
// []
await storageFoundation.getRemainingCapacity()
// 100
rstz commented 3 years ago

Thank you for the report! This is indeed working "as intended", due to our peculiar definition of remaining capacity: it's the amount of extra bytes you can write to disk without having to requesting additional capacity.

I agree that we should reconsider this behaviour and / or explain it better.