Wrapped DataInputStream API?



Hi,

I am trying to use Gjs to build a trivial log parser, but I fail
already at trying to read single lines:

#!/usr/bin/env gjs

const Gio = imports.gi.Gio;
const DataInputStream = imports.gi.Gio.DataInputStream;

function construct_dict(filename) {
        let f = Gio.file_new_for_path(filename);
        print(Gio);
        let read = f.read(null);
        print(read);
        let content = new DataInputStream(read);
        print(content);
        let line = content.read_line(null, null);
        print(line);
}

construct_dict("some.log");

Running this code gets me this output:

[object GIRepositoryNamespace]
[object instance proxy GIName:Gio.FileInputStream jsobj 0x6e0100
native 0x6db240]
[object instance proxy GIName:Gio.DataInputStream jsobj 0x6e0140
native 0x6e2020]

(gjs:11917): GLib-GIO-CRITICAL **: g_input_stream_read: assertion
`G_IS_INPUT_STREAM (stream)' failed
null

I really have no idea what the 2 required arguments to read_line should
be. Reading
<http://library.gnome.org/devel/gio/2.25/GDataInputStream.html#g-data-input-stream-read-line>
it says:

char * g_data_input_stream_read_line (GDataInputStream *stream,
gsize *length, GCancellable *cancellable, GError **error);

stream would be the object on which it is called, the length does not
make much sense if I want to read the whole line, I don't want it to be
cancellable and GError... I'd rather not mess with it.

Is there any introspection support or something?

I tried with Seed as well, I get quite similar errors (I heard Seed
handles GError by turning it into exceptions).

regards,
Marek


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