Pregunta

Can anybody give any working example of how to read/write Unicode text files using Javascript and Gjs, possibly using Gio and/or Glib? I'm experienced in Javascript, but these APIs are still alien to me and being quite new technologies, googling is not helping much.

I've seen this one: https://live.gnome.org/Seed/Tutorial/Simple_file_io , but it is Seed based (not Gjs), and seems quite old. I'm getting errors (like too few arguments on Gio.read on line 9) and thus cannot test using Unicode text.

A working snippet will be much helpful. Thanks!

Update: I'm testing on Ubuntu 12.04 64bit.

¿Fue útil?

Solución

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

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

Otros consejos

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

const GLib = imports.gi.GLib;
//...
let fileContents = String(GLib.file_get_contents("/path/to/yourFile")[1]);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top