Comparing version 0.1.0 to 0.1.1
18
index.js
@@ -8,8 +8,8 @@ var fs = require('fs'), | ||
if(arguments.length < 4) { | ||
file_path = file_path; | ||
data = data; | ||
options = null; | ||
cb = arguments[2]; | ||
file_path = file_path; | ||
data = data; | ||
cb = options | ||
options = null; | ||
}else if (arguments.length < 3) { | ||
throw Error('Arguments should be three or four.') | ||
throw Error('Arguments should be three or four.') | ||
} | ||
@@ -22,3 +22,3 @@ dir_url= path.dirname(file_path) | ||
_create_fs(dir_path, function() { | ||
_file_write(ori_path, data, options, cb) | ||
_file_write(ori_path, data, options, cb) | ||
}) | ||
@@ -36,7 +36,7 @@ } | ||
function _file_write(dir, data, opt, cb) { | ||
fs.writeFile(dir, data, opt, function(err) { | ||
fs.writeFile(dir, data, opt, function(err) { | ||
if(err) | ||
throw Error(err) | ||
cb(null) | ||
throw Error(err) | ||
cb(null) | ||
}) | ||
} |
{ | ||
"name": "file-save", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "auto create path and just save the file!", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# Save file | ||
[![Build Status](https://travis-ci.org/chilijung/file-save.png)](https://travis-ci.org/chilijung/file-save) | ||
Just save the file!!!! Auto create folder path and just save the file. | ||
@@ -4,0 +6,0 @@ |
17
test.js
var should = require('should'); | ||
var fs = require('fs'); | ||
var fileSave = require('./'); | ||
describe('should save to the file', function() { | ||
it('should save to sample folder', function() { | ||
describe('should save the file test', function() { | ||
it('should save to sample folder', function(cb) { | ||
fileSave('sample/test', 'hello world', function(result) { | ||
should.not.exist(result); | ||
should.not.exist(result); | ||
cb(); | ||
}) | ||
}) | ||
it('should read the data in sample/test', function(cb) { | ||
fs.readFile(__dirname + '/sample/test', {encoding: 'utf-8'}, function(err, data) { | ||
if(err) | ||
throw err; | ||
data.should.equal('hello world'); | ||
cb() | ||
}) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
2998
7
54
37
2