GNOME Bugzilla – Bug 730067
Gio.File.replace_contents_async is garbling the output file
Last modified: 2014-08-24 05:24: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.
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 ***