From c80c9e765f7ba6c3ba5d5e78f90fe37f58b1e818 Mon Sep 17 00:00:00 2001 From: Rory MacQueen Date: Tue, 6 Aug 2013 00:12:19 -0700 Subject: Added utility functions for reading and writing to temporary files [endlessm/eos-sdk#220] --- wikipedia/utils.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/wikipedia/utils.js b/wikipedia/utils.js index 662b2b4..234efcd 100644 --- a/wikipedia/utils.js +++ b/wikipedia/utils.js @@ -1,5 +1,6 @@ const Gio = imports.gi.Gio; const GdkPixbuf = imports.gi.GdkPixbuf; +const GLib = imports.gi.GLib; const set_default = function(obj, key, val) { // Similar to python's dict.setdefault(key, val) @@ -47,14 +48,25 @@ function load_file_from_resource(filename) { return data[0]; } -function get_uri_for_relative_path(relative_path){ +function get_path_for_relative_path(relative_path){ let file = Gio.file_new_for_path(relative_path); - return file.get_uri(); + return file.get_path(); } function write_contents_to_file(filename, content){ let file = Gio.file_new_for_path(filename); file.replace_contents(content, null, false, 0, null); + return file.get_uri(); +} + +function write_contents_to_temp_file(name, content){ + let file = Gio.file_new_tmp(name + "XXXXXX")[0]; + file.replace_contents(content, null, false, 0, null); + return file.get_uri(); +} + +function make_temp_dir(name){ + return GLib.dir_make_tmp(name + "XXXXXX"); } /* -- cgit v1.2.3