Unicode file I / O with Javascript and gjs?

Can someone give some working example of how to read / write Unicode text files using Javascript and Gjs , possibly using Gio and / or Glib? I have experience in Javascript, but these APIs are still foreign to me and, being a completely new technology, the search engine does not help much.

I saw this: https://live.gnome.org/Seed/Tutorial/Simple_file_io , but it is based on seed (not Gjs) and it seems pretty old. I get errors (for example, too few arguments in Gio.read on line 9) and therefore cannot test text in Unicode.

A working snippet will be very helpful. Thanks!

Update . I am testing Ubuntu 12.04 64bit.

+4
source share
2 answers

To get a general idea, you can check out the gio-cat.js example from the gjs source code repository .

You can also check the answer for How to start writing Gnome Shell extensions , which has some links that may help you.

+2
source

If you don't mind reading a text file synchronously, you can use the GLib helper function GLib.file_get_contents (String fileName) :

const GLib = imports.gi.GLib; //... let fileContents = String(GLib.file_get_contents("/path/to/yourFile")[1]); 
0
source

All Articles