Re: Javascript unicode problem

Hello Sam:

I ran this code in an extension and it works.  data.txt is UTF-8.

let [success, data] = GLib.file_get_contents('/home/bogwan/data.txt');
let byteData = imports.byteArray.fromString(data.toString(), "UTF-8");
GLib.file_set_contents('/home/bogwan/data2.txt', byteData,


On Wed, 2012-12-26 at 11:34 +0000, Sam Bull wrote:
> Hi guys,
> I hope this is the right place to post, I'm working on a shell
> extension, and need help with a few points to finish it up.
> The most pressing concern, before I can consider the extension usable,
> is when saving data to a file.
> I have used GLib.file_get_contents() to get the contents of a file, and
> this works fine, converting it into a string I can use this for my
> extension without a problem (everything works as expected).
> The issue is when I save the data back into a file with
> GLib.file_set_contents(), this causes the data to be corrupted on
> non-ASCII characters. If I'm not mistaken, it appears to be losing the
> first byte of any 2 byte character.
> Do I need to do something to convert the string to another format or
> anything, to make this work?
> Thanks for any help,
> Sam Bull
> _______________________________________________
> gnome-shell-list mailing list
> gnome-shell-list gnome org

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