diff --git a/app.js b/example/app.js similarity index 68% rename from app.js rename to example/app.js index 22ffcf7..f26f22d 100644 --- a/app.js +++ b/example/app.js @@ -1,6 +1,7 @@ -var storage = require('./lib/index'); +var storage = require('../lib/index'); +var path = require('path'); -var client = storage.createClient({ +var rs = storage.createClient({ provider: 'rackspace', username: 'strongloop', apiKey: 'your-rackspace-api-key' @@ -8,7 +9,7 @@ var client = storage.createClient({ // Container -client.getContainers(function (err, containers) { +rs.getContainers(function (err, containers) { if (err) { console.error(err); return; @@ -58,3 +59,25 @@ s3.getContainers(function (err, containers) { }); }); }); + +var fs = storage.createClient({ + provider: 'filesystem', + root: path.join(__dirname, 'storage') +}); + +// Container + +fs.getContainers(function (err, containers) { + if (err) { + console.error(err); + return; + } + containers.forEach(function (c) { + console.log('filesystem: ', c.name); + c.getFiles(function (err, files) { + files.forEach(function (f) { + console.log('....', f.name); + }); + }); + }); +}); diff --git a/example/storage/container1/f1.txt b/example/storage/container1/f1.txt new file mode 100644 index 0000000..1652405 --- /dev/null +++ b/example/storage/container1/f1.txt @@ -0,0 +1 @@ +Hello.... \ No newline at end of file diff --git a/example/storage/container1/f1_downloaded.txt b/example/storage/container1/f1_downloaded.txt new file mode 100644 index 0000000..1652405 --- /dev/null +++ b/example/storage/container1/f1_downloaded.txt @@ -0,0 +1 @@ +Hello.... \ No newline at end of file diff --git a/example/storage/container2/f2.txt b/example/storage/container2/f2.txt new file mode 100644 index 0000000..1652405 --- /dev/null +++ b/example/storage/container2/f2.txt @@ -0,0 +1 @@ +Hello.... \ No newline at end of file diff --git a/lib/providers/filesystem/container.js b/lib/providers/filesystem/container.js index dd83daf..43a4b05 100644 --- a/lib/providers/filesystem/container.js +++ b/lib/providers/filesystem/container.js @@ -1,7 +1,9 @@ var base = require('pkgcloud').storage; var util = require('util'); -var Container = exports.Container = function Container(client, details) { +exports.Container = Container; + +function Container(client, details) { base.Container.call(this, client, details); }; @@ -13,4 +15,4 @@ Container.prototype._setProperties = function(details) { this[k] = details[k]; } } -} \ No newline at end of file +} diff --git a/lib/providers/filesystem/file.js b/lib/providers/filesystem/file.js index 86709a0..c280c68 100644 --- a/lib/providers/filesystem/file.js +++ b/lib/providers/filesystem/file.js @@ -1,7 +1,9 @@ var base = require('pkgcloud').storage; var util = require('util'); -var File = exports.File = function File(client, details) { +exports.File = File; + +function File(client, details) { base.File.call(this, client, details); }; diff --git a/lib/providers/filesystem/index.js b/lib/providers/filesystem/index.js index 8f93a07..4d90d07 100644 --- a/lib/providers/filesystem/index.js +++ b/lib/providers/filesystem/index.js @@ -55,7 +55,7 @@ FileSystemProvider.prototype.getContainers = function (cb) { for (var p in stat) { props[p] = stat[p]; } - var container = new Container(this, props); + var container = new Container(self, props); containers.push(container); } }); @@ -140,7 +140,11 @@ FileSystemProvider.prototype.download = function (options, cb) { } -FileSystemProvider.prototype.getFiles = function (container, cb) { +FileSystemProvider.prototype.getFiles = function (container, download, cb) { + if (typeof download === 'function' && !(download instanceof RegExp)) { + cb = download; + download = false; + } var self = this; if (!validateName(container, cb)) return; var dir = path.join(this.root, container);