fs-promise
Advanced tools
Comparing version 0.0.1 to 0.0.2
11
index.js
@@ -6,3 +6,4 @@ 'use strict'; | ||
slice = Array.prototype.slice, | ||
noError = ['exists', 'existsSync']; | ||
noError = /exists/, | ||
returnValue = /Sync$|watch|(Read|Write)Stream$|^Stats$/; | ||
@@ -22,6 +23,8 @@ try { | ||
if (typeof func == 'function') | ||
if(noError.indexOf(key) < 0){ | ||
if(returnValue.test(key)){ | ||
exports[key] = fs[key]; | ||
} else if(noError.test(key)){ | ||
exports[key] = promiseWithoutError(func); | ||
} else { | ||
exports[key] = promise(func); | ||
} else { | ||
exports[key] = promiseWithoutError(func); | ||
} | ||
@@ -28,0 +31,0 @@ }); |
{ | ||
"name": "fs-promise", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Filesystem methods as promises, with optional fs-extra and fs-graceful dependencies", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -5,4 +5,5 @@ # fs-promise | ||
Proxies all `fs` modules exposing them as Promises/A+ compatible promises (when, Q, etc). | ||
Proxies all async `fs` methods exposing them as Promises/A+ compatible promises (when, Q, etc). | ||
Passes all sync methods through as values. | ||
Also exposes to `graceful-fs` and/or `fs-extra` methods if they are installed. |
@@ -7,2 +7,3 @@ 'use strict'; | ||
assert = require('assert'), | ||
Promise = require('promise'), | ||
testdir = path.join(__dirname, 'tmp'); | ||
@@ -21,8 +22,40 @@ | ||
return fsp.createFile(file('hello')).then(readtmp).then(function(files){ | ||
assert.deepEqual(files.sort(), ['hello']); | ||
return fsp.createFile(file('world')); | ||
}).then(readtmp).then(function(files){ | ||
assert.deepEqual(files.sort(), ['hello', 'world']); | ||
}); | ||
assert.deepEqual(files.sort(), ['hello']); | ||
return fsp.createFile(file('world')); | ||
}).then(readtmp).then(function(files){ | ||
assert.deepEqual(files.sort(), ['hello', 'world']); | ||
}); | ||
}); | ||
it('should pass through Sync as value', function(){ | ||
return fsp.createFile(file('hello')).then(function(files){ | ||
assert(fsp.existsSync(file('hello'))); | ||
assert(!fsp.existsSync(file('world'))); | ||
return fsp.createFile(file('world')); | ||
}).then(readtmp).then(function(files){ | ||
assert(fsp.existsSync(file('hello'))); | ||
assert(fsp.existsSync(file('world'))); | ||
}); | ||
}); | ||
it('should copy with pipe read/write stream', function(){ | ||
return fsp.writeFile(file('hello1'), 'hello world').then(function(){ | ||
return fsp.readFile(file('hello1'), {encoding:'utf8'}); | ||
}).then(function(contents){ | ||
assert.equal(contents, 'hello world'); | ||
var read = fsp.createReadStream(file('hello1')), | ||
write = fsp.createWriteStream(file('hello2')), | ||
promise = new Promise(function(resolve, reject){ | ||
read.on('end', resolve); | ||
write.on('error', reject); | ||
read.on('error', reject); | ||
}); | ||
read.pipe(write); | ||
return promise; | ||
}).then(function(){ | ||
return fsp.readFile(file('hello2'), {encoding:'utf8'}); | ||
}).then(function(contents){ | ||
assert.equal(contents, 'hello world'); | ||
}); | ||
}); | ||
}); | ||
@@ -38,4 +71,3 @@ | ||
return function(){ | ||
return fsp.exists(testdir) | ||
.then(function(exists){ | ||
return fsp.exists(testdir).then(function(exists){ | ||
assert.equal(exists, shouldExist); | ||
@@ -42,0 +74,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5609
117
9