Skip to content

files

files provides the following functionalities:

  • Read and write files to and from the local file system
  • Monitor files for changes
  • Drag files
import { files } from 'miletus';

files.saveTextFile('path_to_file', 'Contents of my text file!');

Methods

loadTextFile(filename)

  • filename string - Path to the file to be loaded.

Load the contents of filename.

Returns Promise<string> - Resolves with the contents of the file.

saveTextFile(filename, content)

  • filename string - Save the file to this path.
  • content string - The text content to be written to the file.

Save content to filename.

loadBinaryFile(filename)

  • filename string - Path to the file to be loaded.

Load the contents of filename as binary data.

Returns Promise<ArrayBuffer> - Resolves with an ArrayBuffer containing the contents of the file.

saveBinaryFile(filename, content)

  • filename string - Save the file to this path.
  • content ArrayBuffer - The binary data to be written to the file.

Save content to filename.

watchFile(filename, [callback])

  • filename string - Path to the file to be watched
  • callback Function (optional) - It's called when changes happens to the file.
files.watchFile('path_to_my_file', () => {
    alert('My file has changed!');
})

removeWatch(filename)

  • filename string - Remove filename from the watched files.

removeAllWatches()

Remove all watched files.

startDrag(filename)

  • filename string - Path to file to be dragged.

Events

'file-changed'

Event triggered when a watched file changes. The parameter is the path to the file that changed.

files.on('file-changed', (path) => {
    if (path === 'my_file_path') {
        alert('The following file has changed: ' + path);
    }
})