There and back again

There and back again:

Integrating widgets with device and user data

About the author

This presentation

File IO: Rationale

File I/O features

Mountpoints

Accessing files in a mountpoint

Discouraged characters

Character Reason
:

Used to denote alternate file streams on NTFS file systems, as a path separator on OS X, and used to determine the mountpoint (e.g. C:) on Windows systems.

? Used as a wildcard match on virtually all systems, and explicitly illegal in filenames on Windows systems
* Used as a wildcard match on virtually all systems, and explicitly illegal in filenames on Windows systems
|, < and > Used for pipes and redirection on Unix systems
\ Used as path separator on Windows systems

The ':' problem

Discouraged filenames

The mountpoint protocol

File I/O in relation to widgets

The API

Mounting

opera.io.filesystem.browseForDirectory(
  "someName", // mountpoint://someName/path/to/file
  "",
  myCallback,
  false)
      

Mounting

opera.io.filesystem.browseForDirectory(
  "someName", // mountpoint://someName/path/to/file
  "", // Where to start browsing
  myCallback, 
  false)
    

Mounting

opera.io.filesystem.browseForDirectory(
  "someName", // mountpoint://someName/path/to/file
  "", // Where to start browsing
  myCallback, // called with file when mount is successful
  false)
    

Mounting

opera.io.filesystem.browseForDirectory(
  "someName", // mountpoint://someName/path/to/file
  "", // Where to start browsing
  myCallback, // called with file when mount is successful
  false) // Persistent?
    

Mounting, continued

Unmounting

Working with files

Working with files

var file, files = opera.io.filesystem.mountPoints["someName"];
files.refresh(); // The mountpoint is not live
for (var i = 0; file = files[i]; i++)
{
  if (file.isDirectory)
  {
    // Do something to the directory
  }
  else
  {
    doSomething(file); // Do something to the file
  }
}
    

Opening files

Opening files

function doSomething(file)
{
  var myStream = files.open(file, "r");
}
  

Creating files

var myStream = files.open("somenonexistentfile","w");
 

or:

var file = files.resolve("somenonexistentfile");
var myStream = files.open(file,"w");
  

Working with the stream

Working with the stream

A primitive copyFile implementation

function copyFile( f1, f2 )
{
  var srcStream = f2.open(f2,"r");
  var destStream = f1.open(f1,"rw");
  var srcData = srcStream.read(f2.fileSize);
  srcStream.close();
  destStream.writeBytes(srcData);
  destStream.close();
}

A more practical demo

Known issues

A few words about JavaScript plugins

Standards?

Standards: Widgets

<widget xmlns="http://www.w3.org/ns/widgets" 
        id="http://datadriven.com.au/exampleWidget">
  <api src="http://example.com/fileIO/2.0" optional="optional">
    <api src="http://example.com/fileIO/2.0"></api>
  </api>
</widget>
  

URL time

Questions?