hedit/file

Functions to operate on the currently open file.

Members

static, readonly isDirty :boolean

Returns a value indicating whether any modification to the file has been done since it was open.

static, readonly isOpen :boolean

Returns a boolean indicating whether a file is currently open or not.

static, readonly, nullable name :string

Returns the name of the currently open file, or null if no file is open.

static, readonly size :number

Returns the size in bytes of the currently open file, or -1 if no file is open.

Methods

static commit() → {boolean}

Commits a new revision to the currently open file.

A revision is a group of changes the can be undone together: this means that you can perform multiple insertions and deletions and commit them in a single atomically undoable revision.

Returns:
boolean -

Returns true if the commit succeeded.

static delete(pos, len) → {boolean}

Deletes a portion of the currently open file.

Parameters:
Name Type Description
pos number

Index of the first byte to delete.

len number

How many bytes to delete.

Returns:
boolean -

Returns true if the deletion succeeded.

static insert(pos, data) → {boolean}

Inserts new data into the currently open file.

Parameters:
Name Type Description
pos number

Position of the insertion.

data string

Data to insert.

Returns:
boolean -

Returns true if the insertion succeeded.

static read(pos, len) → {ArrayBuffer}

Reads a portion of the currently open file.

Parameters:
Name Type Description
pos number

Index of the first byte to read.

len number

How many bytes to read.

Returns:
ArrayBuffer -

ArrayBuffer with the contents of the file.

static redo() → {boolean}

Reapplies the last undone change to the currently open file.

Returns:
boolean -

Returns true if the file changed, false otherwise.

static undo() → {boolean}

Reverts the last change applied to the currently open file.

Returns:
boolean -

Returns true if the file changed, false otherwise.