After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 605862 - libsoup scrambles binary data
libsoup scrambles binary data
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Bindings
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2010-01-01 20:58 UTC by Pontus Östlund
Modified: 2010-01-25 09:09 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Pontus Östlund 2010-01-01 20:58:23 UTC
It seems libsoup doesn't handle binary files like images and such. I asked on the libsoup mailing list and was suggested it was a Vala implementation problem (http://markmail.org/message/miwspdv5oknzq3ct)

This example program given an image of 4 bytes when it's actually 444 k.

===============================================================================

//! download-binary.vala
//!
//! compile: 
//! valac -o test --pkg libsoup-2.4 --pkg gio-2.0 --thread download-binary.vala

int main(string[] args)
{
  var url = "http://www.poppa.se/blog/data/images/gnome-shield-4.jpg";
  var sess = new Soup.SessionSync();
  var mess = new Soup.Message("GET", url);

  sess.add_feature = new Soup.Logger(Soup.LoggerLogLevel.HEADERS, -1);
  sess.send_message(mess);

  file_put_contents(Path.get_basename(url), mess.response_body.data);

  return 0;
}

void file_put_contents(string file, string contents)
{
  try {
    var f = File.new_for_path(file);

    if (f.query_exists(null))
      f.delete(null);

    var fs = f.create(FileCreateFlags.NONE, null);
    if (!f.query_exists(null)) {
      warning("Unable to create file \"%s\"!", file);
      return;
    }
    var ds = new DataOutputStream(fs);
    ds.put_string(contents, null);
  }
  catch (Error e) {
    warning("Error writing file: %s", e.message);
  }
}

===============================================================================

I apologize if this actually is not a bug but rather a mis-usage from my side.
Comment 1 zarevucky.jiri 2010-01-02 05:32:20 UTC
That's definitely a bindings bug (could you change the component?). MessageBody#data should be uint8[] rather than a string.
Comment 2 Pontus Östlund 2010-01-02 11:18:42 UTC
I changed the "component" to "Bindings".

Thank you.
Comment 3 Evan Nemerson 2010-01-25 09:09:24 UTC
commit 6ffe00e3fa8e1cad4e965d087ab1a9c312e1bd8f
Author: Evan Nemerson <evan@coeus-group.com>
Date:   Mon Jan 25 01:07:03 2010 -0800

    libsoup-2.4: SoupMessageBody.data should be uing8[], not string.
    
    Fixes bug 605862.