Re: Wrapped DataInputStream API?



On 11/24/2010 11:38 PM, Marek Kubica wrote:
On Wed, 24 Nov 2010 22:57:57 +0100
Marek Kubica<marek xivilization net>  wrote:

Your code works in Seed just fine, but interestingly, it fails so in
Gjs, because "Error: Failed to convert UTF-8 string to JS string:
Invalid byte sequence in conversion input"

Oh, wait, I didn't test enough:

Gio = imports.gi.Gio;
GLib = imports.gi.GLib;

function construct_dict(filename) {
         var f = GLib.file_get_contents(filename);
         print(f);
         print(f.content);
}

construct_dict("abc");

where abc is a trivial file returns

true,This is a test
this too
,24
undefined

in Gjs (= works)

and
1
[undefined]

in Seed (= does not work)

In seed you should use f.contents, not f.content. Also, try f.value.
(To see if there are other values in f, print Object.keys(f))

Once I try my "real" log file, Gjs fails with "Error: Failed to convert
UTF-8 string to JS string: Invalid byte sequence in conversion input"

Perhaps you have non-UTF-8 strings in your log-file?

One way to read files line by line in seed is this:

var file = Gio.file_new_for_path(name);
var fstream = file.read();
var dstream = new Gio.DataInputStream.c_new(fstream);

var line;
while((line = dstream.read_line())!=undefined) {
   print(line);
}

fstream.close();

Don't know if it works in Gjs.

and Seed just keeps on doing nothing.

Versions: Seed 2.31.91, Gjs 0.7.7, gobject-introspection 0.9.12, glib
2.26.1

Any idea why Gjs fails to read my file?

/Jonatan


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