Skip to content

Instantly share code, notes, and snippets.

@humphd
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save humphd/e505d219a19dedbfc649 to your computer and use it in GitHub Desktop.
Save humphd/e505d219a19dedbfc649 to your computer and use it in GitHub Desktop.
MakeDrive Client API Example
// MakeDrive API - https://github.com/mozilla/makedrive
var MakeDrive = require('./path/to/makedrive.js');
// fs API - https://github.com/js-platform/filer#filer
var fs = MakeDrive.fs();
// Use fs right away, with or without network
fs.mkdir('/project', function(err) {
if(err) throw err;
fs.writeFile('/project/index.html', '<p>Hello World!</p>', function(err) {
if(err) throw err;
// /project/index.html is now written to disk
});
});
// When you want to sync, get the fs' sync object
var sync = fs.sync;
// Listen for events you care about
sync.on('error', function(err) {
// There was an error during syncing
});
sync.on('connected', function() {
// Connected to sync server
});
sync.on('disconnected', function() {
// Disconnected from sync server
});
sync.on('syncing', function() {
// Syncing with server
});
sync.on('completed', function() {
// Completed syncing with server
});
// Connect to the server
sync.connect('ws://server-url.com');
// [Optional, if in manual mode] Request an upstream sync with the server
sync.request();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment