Class: FileReaderBackend

backend/FileReader.FileReaderBackend(controller, container)

Browser FileReader backend.

Constructor

new FileReaderBackend(controller, container)

Initialize a Sozi backend based on the FileReader API.

Parameters:
Name Type Description
controller module:Controller.Controller

A controller instance.

container HTMLElement

The element that will contain the menu for choosing a backend.

Source:

Extends

Members

autosavedFiles :Array

A list of files to save automatically.

This is an array of file descriptors. The actual type of the elements depends on the platform.

Type:
  • Array
Overrides:
Source:

controller :module:Controller.Controller

The controller for this backend.

Type:
Overrides:
Source:

fileInput :HTMLInputElement

A hidden HTML file input element to open a file chooser.

Type:
  • HTMLInputElement
Source:

(readonly) hasOutdatedFiles :boolean

Check whether at least one file in the autosaved file list needs saving.

This is an accessor that uses the needsSaving function passed to autosave. Returns true if at least one file has unsaved modifications.

Type:
  • boolean
Overrides:
Source:

Methods

autosave(fileDescriptor, needsSaving, getData)

Add the given file to the list of files to save automatically.

Parameters:
Name Type Description
fileDescriptor any

The file to autosave (backend-dependent).

needsSaving function

A function that returns true if the file needs saving.

getData function

A function that returns the data to save.

Overrides:
Source:

create(name, location, mimeType, data) → {Promise}

Create a new file.

Parameters:
Name Type Description
name string

The name of the file to create.

location any

The location of the file to create (backend-dependent).

mimeType string

The MIME type of the file to create.

data string

The content of the file to create.

Overrides:
Source:
Returns:
  • A promise that resolves to a file descriptor.
Type
Promise

doAutosave() → {Promise.<Array>}

Save all files previously added to the autosaved file list.

Typically, we want to call this method each time the editor loses focus and when the editor closes.

Overrides:
Source:
Returns:
  • A promise that resolves when all autosaved files have been saved.
Type
Promise.<Array>

find(name, location) → {Promise}

Find a file.

Parameters:
Name Type Description
name string

The base name of the file.

location any

The location of the file (backend-dependent).

Overrides:
Source:
Returns:
  • A promise that resolves to a file descriptor, rejected if not found.
Type
Promise

getLocation(fileDescriptor) → {string}

Return the location of a file.

Parameters:
Name Type Description
fileDescriptor any

A file descriptor (backend-dependent).

Overrides:
Source:
Returns:

The file location.

Type
string

getName(fileDescriptor) → {string}

Return the base name of a file.

Parameters:
Name Type Description
fileDescriptor any

A file descriptor (backend-dependent).

Overrides:
Source:
Returns:

The file name.

Type
string

load(fileDescriptor) → {Promise.<string>}

Load a file.

This method loads a file and returns a promise with the content of this file.

Parameters:
Name Type Description
fileDescriptor any

A file to load (backend-dependent).

Overrides:
Source:
Returns:
  • A promise that resolves to the content of the file.
Type
Promise.<string>

loadSync(fileDescriptor) → {string}

Load a file synchronously.

Parameters:
Name Type Description
fileDescriptor any

A file to load (backend-dependent).

Overrides:
Source:
Returns:
  • The content of the file.
Type
string

openFileChooser()

Open a file chooser.

This method opens a file dialog to open an SVG document.

Overrides:
Source:

sameFile(fd1, fd2) → {boolean}

Compare two file descriptors.

Parameters:
Name Type Description
fd1 any

A file descriptor (backend-dependent).

fd2 any

A file descriptor (backend-dependent).

Overrides:
Source:
Returns:
  • true if fd1 and fd2 represent the same file.
Type
boolean

save(fileDescriptor, data) → {Promise}

Save data to an existing file.

Parameters:
Name Type Description
fileDescriptor any

The file to save (backend-dependent).

data string

The new content of the file.

Overrides:
Source:
Returns:
  • A promise that resolves to the given file descriptor.
Type
Promise

saveOutdatedFiles() → {Promise.<Array>}

Save all outdated files.

This method calls save for each file in the autosaved file list where needsSaving returns true.

It uses the function getData passed to autosave to write the new file content.

Overrides:
Source:
Returns:
  • A promise that resolves when all autosaved files have been saved.
Type
Promise.<Array>

toggleDevTools()

Show or hide the development tools of the current web browser.

Overrides:
Source: