Returns a DOMRequest for a File. Upon success, you receive a read-only "snapshot" of file's content in the form of a File instance (that can be used anywhere a Blob is accepted, like FileReader, XMLHttpRequest, etc).

When created, the LockedFile is active. This LockedFile is the only object with write access to the actual underlying file. Operations on a LockedFile are performed in isolation, meaning that once a LockedFile is active, all operations of this LockedFile are guaranteed to happen sequentially on the underlying file without being interleaved with operations from other LockedFiles.

When the LockedFile becomes inactive, trying to perform read/write operations on the via using the same LockedFile will throw an error.

location

Offset in the file. This value is changed automatically after every read and every write. Reads and writes occur starting at the location. null means end-of-file

getMetadata(parameters)

Returns a FileRequest for metadata. The argument is an object with parameter names as object keys and booleans as value to retrieve the given properties asynchronously. No value means true. Currently, the possible parameters are size and lastModified.

readAsArrayBuffer(size)

Returns a FileRequest for an ArrayBuffer of the given size. The operation starts at the location. Moves location by the number of read bytes.

readAsText(size [, encoding])

Returns a FileRequest for a string of the given size with the provided encoding. The operation starts at the location. Moves location by the number of read bytes. Works the same way as the equivalent method in the FileReader API.

Returns a FileRequest for the success or failure of the append operation. The value is appended at the end of the file, regardless of the location. After the data is appended, location is set to null.

truncate([size])

Returns a FileRequest for the success or failure of the truncate operation.

If the method is called with a single argument, after a successful truncate, what remains on the file are the first size bytes regardless of the location.

If the method is called with no argument, what remains is the location first bytes.

flush()

This forces the buffered data to be transfered to disk. After a success notified by the returned FileRequest, you can be guaranteed that if the application crashes or is inadvertedly interrupted, the data is on disk.

abort()

Makes the LockedFile inactive and cancels all not already perfomed operations.

complete, abort, error events

FileRequest interface

An object of this type is returned by all asynchronous operations of the LockedFile interface. It inherits from DOMRequest and is similar to IDBRequest, with the addition of the onprogress event. Upon success, the, the result of the requested file operation is accessible from the result property.

Description

Pourquoi une API différente de FileWriter?

The FileWriter specification defines FileWriters, objects aiming at representing editable files. Discussions on public-webapps led to the conclusion that the API would poorly behave in the case of different entities writing concurrently on the same file. The outcome of this discussion is the FileHandle API with its LockedFile and transaction mechanim.