File.js
authorAlan Knowles <alan@akbkhome.com>
Fri, 30 Dec 2011 06:33:37 +0000 (14:33 +0800)
committerAlan Knowles <alan@akbkhome.com>
Fri, 30 Dec 2011 06:33:37 +0000 (14:33 +0800)
File.js

diff --git a/File.js b/File.js
index f7ae90c..93cae90 100755 (executable)
--- a/File.js
+++ b/File.js
@@ -2,7 +2,8 @@
 GLib = imports.gi.GLib;
 Gio = imports.gi.Gio;
 
-String  = imports.String.String; 
+String  = imports.String.String;
+
 /**
 * @class File
 * @singleton
@@ -204,6 +205,20 @@ var File = {
         var data_out = new Gio.DataOutputStream({base_stream:f.replace(null, false, Gio.FileCreateFlags.NONE, null)});
         data_out.put_string(string, null);
         data_out.close(null);
+    },
+        /**
+     * write a string to file
+     * @param {String} pathFile to write to
+     * @param {String} string  Contents of file.
+     * 
+     */
+    writeBinary : function (path, string) {
+        var f = Gio.file_new_for_path(String(path));
+        var data_out = new Gio.DataOutputStream({base_stream:f.replace(null, false, Gio.FileCreateFlags.NONE, null)});
+        for(var i =0; i < string.length) {
+            data_out.put_byte(string[i], null);
+        }
+        data_out.close(null);
     },
     /**
      * append a string to a file
@@ -276,6 +291,22 @@ var File = {
         
         return dest.make_directory(null, null);
     },
+    
+    /**
+     * make a directory..
+     * @param {String} dstPath directory to make
+     */
+    mkdirall : function (destPath) {
+        var parent = File.dirname(destPath);
+        if (!File.exists(parent)) {
+            File.mkdirall(parent);
+        }
+        if (!File.exists(destPath)) {
+            return File.mkdir(destPath); 
+        }
+        return true;
+    },
+    
     /**
      * copy a File
      * @param {String} src source path