Class: GDFileWriter

GDFileWriter(file, append)

This class writes to the mobile device file system.

Constructor

new GDFileWriter(file, append)

Parameters:
Name Type Description
file file File object containing file properties
append bool If true write to the end of the file, otherwise overwrite the file
Source:

Methods

abort()

Abort writing file.
Source:
Example
requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
    var path = "file.txt",
        options = {create: true, exclusive: false};

    fileSystem.root.getFile(path, options, function (file) {
        file.createWriter(function (writer) {
            writer.write("text");
            writer.abort();
            writer.onabort = function() {
                console.log("Writing was aborted");
            };
        }, null);
    }, null);
}, null);

seek(offset)

Moves the file pointer to the location specified. If the offset is a negative number the position of the file pointer is rewound. If the offset is greater than the file size the position is set to the end of the file.
Parameters:
Name Type Description
offset integer Is the location to move the file pointer to.
Source:
Example
requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
    var path = "file.txt",
        options = {create: true, exclusive: false};

    fileSystem.root.getFile(path, options, function (file) {
        file.createWriter(function (writer) {
            writer.onwriteend = function() {
                console.log("Content was written to the file");
            };
            writer.write("text");
            writer.seek(0); // Pointer is at the beginning of the file now
        }, null);
    }, null);
}, null);

truncate(size)

Truncates the file to the size specified.
Parameters:
Name Type Description
size integer Size to chop the file at.
Source:
Example
requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
    var path = "file.txt",
        options = {create: true, exclusive: false};

    fileSystem.root.getFile(path, options, function (file) {
        file.createWriter(function (writer) {
            writer.onwriteend = function() {
                console.log("Content was written to the file");
            };
            writer.write("text");
            writer.truncate(2); // now content of file will be "te"
        }, null);
    }, null);
}, null);

write(data)

Writes data to the file
Parameters:
Name Type Description
data string Data to be written. Supports string and binary (Blob and ArrayBuffer)
Source:
Example
requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
    var path = "file.txt",
        options = {create: true, exclusive: false};

    fileSystem.root.getFile(path, options, function (file) {
        file.createWriter(function (writer) {
            writer.onwriteend = function() {
                console.log("Content was written to the file");
            };
            writer.write("text");
        }, null);
    }, null);
}, null);