fstorm
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -92,3 +92,3 @@ | ||
fs.writeFile( filename, content, pending.options , function(err){ | ||
fs.writeFile( filename, typeof content === 'function'? content(): content, pending.options , function(err){ | ||
self.status = IDLE; | ||
@@ -114,2 +114,3 @@ callback && callback(err, 1); | ||
var cache = FileStorm.cache = getCache(1000); | ||
@@ -116,0 +117,0 @@ |
{ | ||
"name": "fstorm", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "writing file more efficient and safety with no pain", | ||
@@ -28,3 +28,2 @@ "main": "index.js", | ||
"mocha": "^2.2.5", | ||
"should": "^6.0.3", | ||
"steno": "^0.3.2" | ||
@@ -31,0 +30,0 @@ }, |
@@ -1,2 +0,2 @@ | ||
# fstorm | ||
# fstorm [![Build Status](https://travis-ci.org/leeluolee/fstorm.svg?branch=master)](https://travis-ci.org/leeluolee/fstorm) | ||
@@ -160,3 +160,3 @@ > writing file like a storm , but always get the expected result | ||
```js | ||
var wirter = fstorm(filename); | ||
var writer = fstorm(filename); | ||
``` | ||
@@ -192,3 +192,3 @@ | ||
Temporary, only 'end' is emitted by writer, mean that writer is stable (or no new operation is blocked). | ||
Temporary, only `end` and `error` is emitted by writer, mean that writer is stable (or no new operation is blocked). | ||
@@ -208,3 +208,17 @@ - end | ||
- error | ||
```js | ||
var writer = fstorm('.folder/not/exists/db.json') | ||
writer.on('error', function(err){ | ||
assert(err.code === 'ENOENT') // true | ||
}) | ||
writer.write('2') | ||
``` | ||
### Contribution | ||
@@ -211,0 +225,0 @@ |
@@ -126,25 +126,41 @@ | ||
}) | ||
// it("when pass function , it should emit get the function's result as content", function( done ){ | ||
// var filename = path.join(__dirname, './data/it4.txt') | ||
// var writer = fstorm(filename); | ||
// var endCount = 0; | ||
// writer.on('end', function(){ | ||
// endCount++; | ||
it('writer.destroy should remove the instance from cache', function(){ | ||
var filename = path.join(__dirname, './data/xxx/it5.txt') // dir is not exist | ||
var writer1 = fstorm(filename); | ||
var writer2 = fstorm(filename); | ||
expect(writer1).to.equal(writer2); | ||
// if(endCount === 2){ | ||
// var content = fs.readFileSync(filename, 'utf8'); | ||
// expect(JSON.parse(content)).to.be.eql({code:4}); | ||
// done(); | ||
// } | ||
// }) | ||
writer1.destroy(); | ||
// writer.write(function(){JSON.stringify({code:2})}) | ||
// writer.write(function(){JSON.stringify({code:3})}) | ||
var writer3 = fstorm(filename); | ||
expect(writer3).to.not.equal(writer1) | ||
}) | ||
// process.nextTick(function(){ | ||
// writer.write(function(){JSON.stringify({code:4})}) | ||
// }) | ||
it('writer.write accept function as content', function(done){ | ||
var filename = path.join(__dirname, './data/it6.txt') | ||
var writer = fstorm(filename); | ||
var endCount = 0; | ||
// }) | ||
writer.on('end', function(){ | ||
var content = fs.readFileSync(filename, 'utf8'); | ||
expect( content ).to.eql(JSON.stringify({code:5})); | ||
done(); | ||
}) | ||
writer.write(function(){return JSON.stringify({code:2})}) | ||
writer.write(function(){return JSON.stringify({code:3})}) | ||
process.nextTick(function(){ | ||
writer.write(function(){return JSON.stringify({code:4})}) | ||
process.nextTick(function(){ | ||
writer.write(function(){return JSON.stringify({code:5})}) | ||
}) | ||
}) | ||
}) | ||
after(function(){ | ||
@@ -151,0 +167,0 @@ fs.readdir(path.join(__dirname, './data'), function(error, filenames){ |
17759
5
337
239