Comparing version 0.0.4 to 0.1.0
{ | ||
"name": "bfg", | ||
"version": "0.0.4", | ||
"version": "0.1.0", | ||
"description": "Big Friendly Gateway creates a read and write stream to various cloud storage providers", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -153,2 +153,18 @@ bfg | ||
## var folder = disk.folder(basepath) | ||
Return a new disk that will save and load files relative to the given basepath | ||
This is useful for partitioning a container for serveral projects. | ||
```js | ||
var app = express(); | ||
var disk = bfg.rackspace(...); | ||
var folder = disk.folder('/subfolder') | ||
fs.createReadStream(__dirname + '/hello.txt').pipe(disk.createWriteStream('/hello.txt')); | ||
``` | ||
The file is saved to '/subfolder/hello.txt' | ||
## events | ||
@@ -155,0 +171,0 @@ |
@@ -12,2 +12,3 @@ #!/usr/bin/env node | ||
.option('-c, --container [value]', 'Rackspace Container', '') | ||
.option('-f, --folder [value]', 'Remote sub-folder', '') | ||
.version(version) | ||
@@ -20,3 +21,4 @@ | ||
region:program.region, | ||
container:program.container | ||
container:program.container, | ||
folder:program.folder | ||
}); | ||
@@ -23,0 +25,0 @@ |
@@ -5,6 +5,7 @@ var EventEmitter = require('events').EventEmitter; | ||
function Disk(driver, container){ | ||
function Disk(driver, container, folder){ | ||
EventEmitter.call(this); | ||
this._driver = driver; | ||
this._container = container; | ||
this._folder = folder || ''; | ||
} | ||
@@ -16,2 +17,6 @@ | ||
Disk.prototype.folder = function(basepath){ | ||
return new Disk(this._driver, this._container, basepath); | ||
} | ||
Disk.prototype.createReadStream = function(filepath){ | ||
@@ -21,3 +26,3 @@ var self = this; | ||
container: this._container, | ||
remote: filepath | ||
remote: this._folder + filepath | ||
}) | ||
@@ -36,3 +41,3 @@ | ||
container: this._container, | ||
remote: filepath | ||
remote: this._folder + filepath | ||
}) | ||
@@ -39,0 +44,0 @@ |
@@ -6,5 +6,6 @@ var Disk = require('./disk'); | ||
rackspace:function(options){ | ||
options = options || {}; | ||
var driver = Rackspace(options); | ||
return new Disk(driver, options.container); | ||
return new Disk(driver, options.container, options.folder); | ||
} | ||
} |
@@ -1,1 +0,1 @@ | ||
hello world 1394986450384 | ||
hello world 1394993440236 |
@@ -1,1 +0,1 @@ | ||
hello world 1394986450384 | ||
hello world 1394993440236 |
@@ -102,2 +102,70 @@ var bfg = require('../src'); | ||
describe('folder', function(){ | ||
it('should upload and download a text file', function(done){ | ||
this.timeout(10000); | ||
var disk = getdisk(); | ||
var folder = disk.folder('/foldertest'); | ||
var time = new Date().getTime(); | ||
var test_string = 'hello world ' + time; | ||
fs.writeFileSync(__dirname + '/fixtures/hello.txt', test_string); | ||
function upload(uploaddone){ | ||
var localsource = fs.createReadStream(__dirname + '/fixtures/hello.txt'); | ||
var remotesink = folder.createWriteStream('/hello.txt'); | ||
remotesink.on('error', function(err){ | ||
throw new Error(err); | ||
}) | ||
localsource.on('end', function(){ | ||
uploaddone(); | ||
}); | ||
localsource.pipe(remotesink); | ||
} | ||
function download(downloaddone){ | ||
var remotesource = disk.createReadStream('/foldertest/hello.txt'); | ||
var localsink = fs.createWriteStream(__dirname + '/fixtures/hello.back.txt'); | ||
remotesource.on('error', function(err){ | ||
throw new Error(err); | ||
}) | ||
remotesource.on('end', function(){ | ||
setTimeout(function(){ | ||
var contentA = fs.readFileSync(__dirname + '/fixtures/hello.txt', 'utf8'); | ||
var contentB = fs.readFileSync(__dirname + '/fixtures/hello.back.txt', 'utf8'); | ||
contentA.should.equal(contentB); | ||
downloaddone(); | ||
}, 500) | ||
}) | ||
remotesource.pipe(localsink); | ||
} | ||
upload(function(){ | ||
setTimeout(function(){ | ||
download(function(){ | ||
done(); | ||
}) | ||
}, 1000); | ||
}) | ||
}) | ||
}) | ||
}) |
14745
291
182