Re: Writing a buffer with UTF-8 content.



I found the problem, faulty reference told me bufferlen has to be
placed after buffer in aruments, this is not true.

Filewriting works, but also freaking ISO-8859-1 instead of UTF-8.

Translating encoding is no option as there are many locale in
this .desktop file  that I have in buffer, and all need to be preserved.

I just want a UTF-8 buffer written to file, nothing more, that should
be possible, no?

If not then I am speechless *facepalm*.

-- 
(o_
//\  Regards, Groeten,
V_/_ Bas Burger.


On Thu, 26 Jul 2012 19:15:30 +0200
Clemens <clemens lab21 org> wrote:

> 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]