The getDeviceStorage method is used to access some storage area available on the device.
This method give access to a storage area from the device's default storage, that is the storage area whose .default attribute is true. This is controlled by the user via Settings App > Media Storage > Default media location (e.g. sdcard, internal memory, etc.) Alternatively, you can use the getDeviceStorages method which returns an Array of DeviceStorage (KaiOS 2.5 version but can be applied to 3.0)objects, one per physical storage area.
Regarding [DeviceStorage] (/docs/api/web-apis/deviceStorage/device-storage/)
- DeviceStorage will be placed **after "navigator.b2g"
- Syntax of method DeviceStorage.enumerate() is deifferent.
The name of the targeted storage area. Firefox OS supports the following areas:
apps: This storage area is used to store the user data needed by apps. As it is critical data, accessing this storage area requires some extra privileges (see below) and is available to certified applications only.
music: This is the storage area where music and sounds are stored.
pictures: This is the storage area where pictures are stored.
sdcard: This is the storage area that gives access to the device's SDCard. sdcard is also used as the name of the device's default internal storage, which is a bit unfortunate and potentially confusing; be aware.
videos: This is the storage area where videos are stored.
This method returns a DeviceStorage object that can be used to manage files on the associated storage area.
DeviceStorage.enumerate() is a new return type replaces DOMCursor since DOMCursor has deprecated already. You can find details of the new return type --- FileIterable and examples of using DeviceStorage.enumerate() in this document. DeviceStorage.enumerate()'s retuen type has been changed to "Filelterable." DEtails below:
FileIterable is declared to be asynchronously iterable, for details about iterable protocol and iterator protocol, please check up Iteration protocols, which introduces the synchronous version of iterable and iterator. MDN page of asynchronous iterable and iterator does not exist yet, however, they are mostly the same, except:
- itor.next() returns a Promise withe the result object.
- Supports for-await-of to loop through the iteration.
- Does not support indexing.
For more details about a asynchronously iterable, please reference the W3C spec at Asynchronously iterable declarations.
Interface of Filelterable and DeviceStorage.enumerate() are as follow:
For example, if there are three files a.txt, b.txt, c.txt in default internal SD card, and we want to list them out.
Use itor.next() to loop through the iteration
Use for await-of to loop through the iteration