[gnome-continuous] jsonutil: Add a helper to serialize pretty JSON in a consistent manner



commit 3a4ae985b99a7b0f9ddc8eac05a99c53bed0c84d
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Mon Sep 30 14:35:26 2013 -0400

    jsonutil: Add a helper to serialize pretty JSON in a consistent manner

 src/js/jsondb.js   |    2 +-
 src/js/jsonutil.js |    8 ++++++--
 2 files changed, 7 insertions(+), 3 deletions(-)
---
diff --git a/src/js/jsondb.js b/src/js/jsondb.js
index 5ef5781..d435d8d 100644
--- a/src/js/jsondb.js
+++ b/src/js/jsondb.js
@@ -130,7 +130,7 @@ const JsonDB = new Lang.Class({
                                                       currentTime.get_month(),
                                                       currentTime.get_day_of_month()]);
 
-       let buf = JSON.stringify(obj, null, "  ");
+       let buf = JsonUtil.serializeJson(obj);
        let csum = GLib.compute_checksum_for_string(GLib.ChecksumType.SHA256, buf, -1);
         
         if (latest && csum == latest[2]) {
diff --git a/src/js/jsonutil.js b/src/js/jsonutil.js
index 24deb88..20b77eb 100644
--- a/src/js/jsonutil.js
+++ b/src/js/jsonutil.js
@@ -22,13 +22,17 @@ const Gio = imports.gi.Gio;
  * Read/write JSON to/from GFile paths, very inefficiently.
  */
 
+function serializeJson(data) {
+    return JSON.stringify(data, null, "  ");
+}
+
 function writeJsonToStream(stream, data, cancellable) {
-    let buf = JSON.stringify(data, null, "  ");
+    let buf = serializeJson(data);
     stream.write_bytes(new GLib.Bytes(buf), cancellable);
 }
 
 function writeJsonToStreamAsync(stream, data, cancellable, onComplete) {
-    let buf = JSON.stringify(data, null, "  ");
+    let buf = serializeJson(data);
     stream.write_bytes_async(new GLib.Bytes(buf), GLib.PRIORITY_DEFAULT,
                             cancellable, function(stream, result) {
                                 let err = null;


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