Re: Re: Wrapped DataInputStream API?



You've hit the wonders of binary handling in javascript.

Currently there is no 'official' way to handle binary data (as far as I could find)

In the situation you have, I suspect you will probably be best using the Gio.ConverterInputStream and the Gio.CharsetConverter

http://www.roojs.org/seed/gir-1.1-gtk-2.0/Gio.ConverterInputStream.html
http://www.roojs.org/seed/gir-1.1-gtk-2.0/Gio.CharsetConverter.html

At some point I guess it will become necessary to work out how to handle this properly (eg. introspection annotations should indicate that something is binary data, and the javascript bindings need to handle binary strings as array's of integers..)

Regards
Alan



 --- On 25/Nov/2010, Marek Kubica wrote: 
> Ok, I think I am slowly loosing my sanity...
> 
> On Wed, 24 Nov 2010 23:48:19 +0100
> Jonatan Liljedahl <lijon kymatica com> wrote:
> 
> > 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))
> 
> I tried both f.contents and f.value, both are undefined in Seed and Gjs
> (Gjs seems to print the file plus some stuff when doing print(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?
> 
> Possibly, as it is from IRC there is potentially everything in there,
> with everybody using a different encoding.
> 
> I tried the same file with Python, decoding as UTF-8 fails there as
> well, so this is the file that's broken. Reading it linewise and
> figuring out what the encoding of the line is, sounds like the best bet.
> 
> > 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.
> 
> That actually works for me as well (and is similar to what I started
> with, except that I did not know about c_new), but only on Seed. Gjs
> seems to require some more arguments to read(), read_line() and can't
> instantiate DataInputStream :/
> 
> regards,
> Marek
> _______________________________________________
> javascript-list mailing list
> javascript-list gnome org
> http://mail.gnome.org/mailman/listinfo/javascript-list



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