Re: Writing a buffer with UTF-8 content.



Am 26.07.2012 18:08, schrieb Yaa101:
Hi all,

I am having trouble writing a buffer with UTF-8 content to a file.

I know that GLib.file_set_contents will not do the job because it
writes ISO-8859-1 instead of UTF-8.

I tried to get it done with this code:

let gFile = Gio.file_new_for_path(this._path);
let gFileOutputStream =
gFile.replace(null, false, Gio.FileCreateFlags.NONE, null);
gFileOutputStream.write(data, datalen, null);
gFileOutputStream.close(null);

GJS throws me a "Unhandled GType GCancellable unpacking GArgument from
Number" and stops.

I cannot find any reference to "Unhandled GType GCancellable unpacking
GArgument from Number" in google.

Can somebody tell me what I am doing wrong, or tell me how to
successfull write a buffer with UTF-8 content to a file?


hi,

have you tried to convert the string before writing?

  http://developer.gnome.org/glib/stable/glib-Character-Set-Conversion.html

i was writing to a file in an extension, there i used

const Me = imports.misc.extensionUtils.getCurrentExtension(); let file = Me.dir.get_child("filename.json"); file.replace_contents(JSON.stringify(this._settings, null, 2), null, false, 0, null); maybe this work (obviously only if you file is in your extension dir) cheers



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]