FileHandle Simple write then read doesn't work

RESOLVED INVALID

Status

()

Core
DOM: Device Interfaces
RESOLVED INVALID
6 years ago
6 years ago

People

(Reporter: David Bruant, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

608 bytes, application/javascript
Details
(Reporter)

Description

6 years ago
Created attachment 702834 [details]
test case

Test case attached.
Since I'm calling the readAsText after the success of the write and both are async, I would expect to have 'yo' written in the file (and the .length to be 2), but I get the empty string. I see the empty string in both Firefox Aurora and Nightly

There is also a probability that I'm misunderstanding the API since I'm discovering it.
(Reporter)

Updated

6 years ago
Blocks: 726593

Comment 1

6 years ago
Just add |lf.location = 0;| before |var text = lf.readAsText(2)|

Each write() increases location by the size of passed text/blob/arraybuffer.

Comment 2

6 years ago
And don't be surprised when the file disappear (after a GC) when you leave the page.
Just add the filehandle to an object store and it won't be deleted.
(Reporter)

Comment 3

6 years ago
(In reply to Jan Varga [:janv] from comment #1)
> Just add |lf.location = 0;| before |var text = lf.readAsText(2)|
Ok. It works with this line. That's not a bug then.
I'll be on dev-webapi to ask further questions.
Thanks :-)
Status: NEW → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.