2

I modified the Writing to a file example such that I can store some text from an input. I am storing the text aaaaaaaaaa to the file and afterwards the shorter bbbbb to the same file with the same function.

Additionally I am using the Reading a file by name example to read the file. I am getting -- with Chromium 15 -- this result:

bbbbbaaaaa

How can I reset the content of a file? The spec just offers getBlob() and append().

1 Answer 1

1

There's a "truncate" method on the FileWriter interface. (It works more like a "setFileSize" method, in that it's possible to "truncate" a file to a larger size than it already has.)

Sign up to request clarification or add additional context in comments.

7 Comments

truncate did it. It took me half an hour not to run in an INVALID_STATE_ERR.
Yes it seems like it can't be called except immediately after opening the file, or something like that; the spec is not super clear.
Have a look on github.com/vitalets/bro-fs where fs.writeFile() truncates file automatically.
@vitalets that looks interesting, but it's for Node, and it's not clear whether this question was about server- or client-side work (though from 2011 it's more likely to be client-side). It's kind-of moot anyway since the HTML5 FileSystem API is defunct.
Nope. It's for browser, but with Node.js compatible API.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.