Re: How to download an image with libsoup and save it to filesystem in gjs



Hi,

Don't forget to reply-all to the list, please — that will help others who run into the same problem.

You aren't using ByteArray correctly there. I suggest double-checking the documentation that I linked.

However, getting the same error actually points to "image.data" being the culprit. Does "image.data" by itself on the line also throw the same exception? It looks like you should use image.get_data() instead, according to the libsoup docs: http://devdocs.baznga.org/soup24~2.56.0/soup.buffer#method-get_data

On Sat, Jun 10, 2017 at 5:10 PM Michael Teuscher <mk teuscher gmail com> wrote:
Thanks for the link, but now the error is getting even worse.

Same line number, same error, completely different code

let a = new ByteArray(image.data.length);
I've got absolutely no clue why 

2017-06-11 1:12 GMT+02:00 <philip chimento gmail com>:
Aha, that is easier, thanks. GLib.Bytes.new_from_bytes doesn't seem to be used correctly - it takes at least an offset and a length parameter? What you want in this case, I think, is a ByteArray. See the documentation here: https://github.com/GNOME/gjs/blob/master/doc/ByteArray.md

GJS console is just an executable ("/usr/bin/gjs") with which you can execute a GJS script directly.


On Sat, Jun 10, 2017 at 3:46 PM Michael Teuscher <mk teuscher gmail com> wrote:
Huff, dont have a lot of experience with the gjs-console, but I can tell you which line fails:


-> let bytes = GLib.Bytes.prototype.new_from_bytes(image.data);
This one is failing with JS ERROR: Error: Failed to convert UTF-8 string to JS string: Invalid byte sequence

I really dont know what is wrong with that line.



2017-06-11 0:35 GMT+02:00 <philip chimento gmail com>:
Is it possible to make a minimal example which isolates the problem? For example, just a script that can be run with gjs-console instead of the whole shell extension?

Your analysis seems plausible. Is the ostream.write_bytes() call trying to convert to UTF8? It should not be, if it's correctly annotated.



On Sat, Jun 10, 2017 at 3:27 PM Michael Teuscher <mk teuscher gmail com> wrote:
Hello,

Thanks for your response, I published the program on my git server.

https://git.scaly.ch/projects/TS/repos/gnome-spotlight/browse

libsoup is returning a byte array but GIO (or something else) tries to convert it to UTF 8 when I want to write it down into a file.

Thanks a lot

Regards
Michael Teuscher




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