Permalink
Browse files

[enhance] runtime, file: Use the asynchrnous write + some fixes on pa…

…th mainupaltion
  • Loading branch information...
1 parent 8c7a57c commit 084a7e424d75497ca2f539c301e62cc0eec97de3 @BourgerieQuentin BourgerieQuentin committed Oct 30, 2012
Showing with 21 additions and 20 deletions.
  1. +21 −20 lib/plugins/unix/bslFile.nodejs
@@ -10,6 +10,7 @@
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var FileSystem = require('fs');
+var Path = require('path');
/** TODO - plugins dependencies */
/** @externType time_t */
@@ -68,20 +69,12 @@ function make_dir(path) {
}
/**
- * @register {string -> string}
+ * @register {string -> string} basename Path.basename
*/
-function basename(path) {
- return path.split("/").pop();
-}
/**
- * @register {string -> string}
+ * @register {string -> string} dirname Path.dirname
*/
-function dirname(path) {
- var r = path.split("/");
- r.pop();
- return r.join("/");
-}
/**
* @register {string -> opa[option(binary)]}
@@ -98,11 +91,12 @@ function content_opt(path) {
* @register {string -> void}
*/
function create_full_path(path) {
- var p = path.split( "/"), path = [ ];
+ var p = path.split(Path.sep), path = [ ];
while (p.length > 0) {
try {
- path.push(p.shift());
- FileSystem.mkdirSync( path.join( "/"));
+ var tmp = p.shift();
+ path.push(tmp);
+ if(tmp != "" && tmp != ".") FileSystem.mkdirSync(path.join(Path.sep));
} catch (e) {
if (e.code != "EEXIST") {
throw e;
@@ -135,15 +129,22 @@ function last_modification(path) {
return FileSystem.statSync(path).mtime;
}
-// WARNING : Binary is not trimed
/**
- * @register {string, binary -> void}
+ * @register {string, binary, continuation(void) -> void}
+ * @cpsBypass
*/
-function write(path, bin) {
- var dir = dirname(path);
- create_full_path(dir);
- FileSystem.writeFileSync(path, bin.contents);
- return js_void;
+function write(path, bin, k) {
+ create_full_path(Path.dirname(path));
+ FileSystem.open(path, 'w', 438, function (err, fd){
+ if(err) {
+ console.error("File.write", err);
+ return_(k, js_void);
+ } else {
+ FileSystem.write(fd, bin.contents, 0, bin.length, 0, function(_1){
+ return_(k, js_void);
+ })
+ }
+ })
}
/**

0 comments on commit 084a7e4

Please sign in to comment.