Comparing version 0.0.2 to 0.0.3
61
index.js
@@ -188,2 +188,3 @@ module.exports = new (function() { | ||
encoding: opts.encoding || null, | ||
format: opts.format || 'text', | ||
flag: opts.flag || 'r' | ||
@@ -214,11 +215,21 @@ }; | ||
switch(options.encoding) { | ||
switch(options.format) { | ||
case null: | ||
case 'text': | ||
reader.readAsText(fd, options.encoding); | ||
break; | ||
case 'binary': | ||
reader.readAsBinaryString(fd.slice()); | ||
reader.readAsBinaryString(fd); | ||
break; | ||
case 'utf8': | ||
reader.readAsText(fd.slice()); | ||
case 'dataURL': | ||
reader.readAsDataURL(fd); | ||
break; | ||
case 'buffer': | ||
reader.readAsArrayBuffer(fd); | ||
break; | ||
default: | ||
reader.readAsText(fd, options.encoding); | ||
} | ||
@@ -291,33 +302,21 @@ }); | ||
if (exists) { | ||
self.open(filename, options.flag, function(error, fd) { | ||
if (error) { | ||
callback(error); | ||
return; | ||
} | ||
var storage = getStorageForPath(filename); | ||
self.write(fd, data, 0, null, 0, callback); | ||
}); | ||
if (!storage) { | ||
callback(new Error('Unable to find entry point for ' + filename + '.')); | ||
return; | ||
} | ||
else { | ||
var storage = getStorageForPath(filename); | ||
if (!storage) { | ||
callback(new Error('Unable to find entry point for ' + filename + '.')); | ||
return; | ||
} | ||
var file = (data instanceof Blob) ? data : new Blob([data], { type: options.mimetype }); | ||
var filepath = getPathWithoutStorageType(filename); | ||
var file = new Blob([data], { type: options.mimetype }); | ||
var filepath = getPathWithoutStorageType(filename); | ||
var request = storage.addNamed(file, filepath); | ||
request.onsuccess = function() | ||
{ | ||
callback(null); | ||
}; | ||
request.onerror = function() | ||
{ | ||
callback(this.error); | ||
}; | ||
} | ||
var request = storage.addNamed(file, filepath); | ||
request.onsuccess = function() | ||
{ | ||
callback(null); | ||
}; | ||
request.onerror = function() | ||
{ | ||
callback(this.error); | ||
}; | ||
}); | ||
@@ -324,0 +323,0 @@ }; |
{ | ||
"name": "ffos-fs", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "fs module for the Firefox OS", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -32,3 +32,4 @@ ffos-fs | ||
- _encoding_ ```String | Null``` default = null, can be 'utf8' or 'binary' | ||
- _format_ ```String | Null``` default = 'text', can be 'text', 'binary', 'dataURL', 'buffer' | ||
- _encoding_ ```String | Null``` default = null, text encoding if _format_ is 'text' | ||
- _flag_ ```String``` default = 'r', can be 'r' or 'w' | ||
@@ -50,3 +51,3 @@ | ||
```javascript | ||
fs.readFile(path, data, [options], callback(error) { ... }); | ||
fs.writeFile(path, data, [options], callback(error) { ... }); | ||
``` | ||
@@ -53,0 +54,0 @@ |
12984
110
299