Add fs to sample

This commit is contained in:
Raymond Feng 2013-06-25 13:06:54 -07:00
parent afb3b99c58
commit 9b0fe46fbd
7 changed files with 42 additions and 8 deletions

View File

@ -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);
});
});
});
});

View File

@ -0,0 +1 @@
Hello....

View File

@ -0,0 +1 @@
Hello....

View File

@ -0,0 +1 @@
Hello....

View File

@ -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];
}
}
}
}

View File

@ -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);
};

View File

@ -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);