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 730067 - Gio.File.replace_contents_async is garbling the output file
Gio.File.replace_contents_async is garbling the output file
Status: RESOLVED DUPLICATE of bug 690525
Product: gjs
Classification: Bindings
Component: general
1.40.x
Other Linux
: Normal normal
: ---
Assigned To: gjs-maint
gjs-maint
Depends on:
Blocks:
 
 
Reported: 2014-05-13 16:28 UTC by Felipe Borges
Modified: 2014-08-24 05:24 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Felipe Borges 2014-05-13 16:28:03 UTC
I've been experiencing a bug while trying to write a buffer to a file using Gio.File's replace_contents_async. It's been writing strange characters to the output.

Here's a code snippet showing this unexpected behavior:

const Gio = imports.gi.Gio;
const Lang = imports.lang;
const Mainloop = imports.mainloop;

let buffer = "lala";
let file = Gio.file_new_for_path("output.json");
file.replace_contents_async(buffer, null, false, Gio.FileCreateFlags.REPLACE_DESTINATION, null, 
    Lang.bind(this, function() {
        log("bye!");
    }));

Mainloop.run();

It's the same when using ByteArray:

const ByteArray = imports.byteArray;
const Gio = imports.gi.Gio;
const Lang = imports.lang;
const Mainloop = imports.mainloop;

let byteArray = ByteArray.fromString('lala');;
let file = Gio.file_new_for_path("output.json");
file.replace_contents_async(byteArray, null, false, Gio.FileCreateFlags.REPLACE_DESTINATION, null, 
    Lang.bind(this, function() {
        log("bye!");
    }));

Mainloop.run();

* Gio.file.replace_contents() works fine.
Comment 1 Simon Feltman 2014-08-24 05:24:03 UTC
You can use: replace_contents_bytes_async() passing it GLib.Bytes. I'm not sure why the fix for this didn't rename the function or skip the broken one though...

*** This bug has been marked as a duplicate of bug 690525 ***