The best way I've found so far is to use DataInput/Output streams. http://www.roojs.com/seed/gir-1.2-gtk-3.0/gjs/Gio.DataInputStream.html
This is an example of some code that writes binary arrays. writeBinaryArray : function (path, stringAr) { var f = Gio.file_new_for_path(String(path)); var data_out = new Gio.DataOutputStream({base_stream:f.replace(null, false, Gio.FileCreateFlags.NONE, null)}); for(var i =0; i < stringAr.length; i++) { data_out.put_byte(stringAr[i], null); if (i % 10000 == 0) { print("wrote " + i + "/" + stringAr.length + "\n"); } } data_out.close(null); }, With a bit of guesswork, you should be able to create an dataInputstream and use the get_byte() method. Regards Alan --- On 05/Aug/2012, gdfc wrote: > Hi! > > I'm currently writing an extension for Gnome Shell using gjs and have to read > some gpsd data from a socket. I've gotten this far: > > const Gio = imports.gi.Gio; > let sockCl = new Gio.SocketClient(); > let sockCon = sockCl.connect_to_host("localhost:2947", null, > null); > let outStr = sockCon.get_output_stream(); > outStr.write('?WATCH={"enable":true,"json":true};', null); > let inStr = sockCon.get_input_stream(); > let b = new Array(128); > inStr.read(b, 1, null); > > However, the read method always fails with the following error: > > Error: Argument 'buffer' (type void) may not be null > > I've tried all read* methods described in the only more or less current gjs > API reference I've found [1], but they all seem to have the same problem. > This is regardless of what type b is -- it can be an array, a string, a > number or even a function, but it doesn't get recognised as anything other > than null. I'm aware of [2] (this is the only web search result I've stumbled > upon), but it is of little help. > > So my question here: does anyone know a way to read from a socket in gjs? It > doesn't have to be Gio, any standard lib would do... I've tried some Soup and > GLib methods, but they don't seem to work either. In Gio, I do at least get > the OutputStream to write reliably... > > Any advice is highly appreciated. Thank you! > > [1] http://www.roojs.com/seed/gir-1.2-gtk-3.0/gjs/Gio.InputStream.html > [2] https://mail.gnome.org/archives/javascript-list/2012-January/msg00003.html > _______________________________________________ > javascript-list mailing list > javascript-list@gnome.org > https://mail.gnome.org/mailman/listinfo/javascript-list _______________________________________________ javascript-list mailing list javascript-list@gnome.org https://mail.gnome.org/mailman/listinfo/javascript-list