[gnome-documents/wip/rishi/onedrive-lo: 9/10] documents: Implement the downloadImpl vfunc for SkydriveDocument



commit fef6e10af125038def773a391b6a4c5c5f71ad99
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu Mar 30 18:23:27 2017 +0200

    documents: Implement the downloadImpl vfunc for SkydriveDocument
    
    https://bugzilla.gnome.org/show_bug.cgi?id=774937

 src/documents.js |   59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 59 insertions(+), 0 deletions(-)
---
diff --git a/src/documents.js b/src/documents.js
index 37d8517..f63690c 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -1184,6 +1184,65 @@ const SkydriveDocument = new Lang.Class({
                  }));
     },
 
+    downloadImpl: function(localFile, cancellable, callback) {
+        this._createZpjEntry(cancellable, Lang.bind(this,
+            function(entry, service, error) {
+                if (error) {
+                    callback(false, error);
+                    return;
+                }
+
+                service.download_file_to_stream_async(entry, cancellable, Lang.bind(this,
+                    function(object, res) {
+                        let inputStream;
+
+                        try {
+                            inputStream = object.download_file_to_stream_finish(res);
+                        } catch (e) {
+                            callback(false, e);
+                            return;
+                        }
+
+                        localFile.replace_async(null,
+                                                false,
+                                                Gio.FileCreateFlags.PRIVATE,
+                                                GLib.PRIORITY_DEFAULT,
+                                                cancellable,
+                                                Lang.bind(this,
+                            function(object, res) {
+                                let outputStream;
+
+                                try {
+                                    outputStream = object.replace_finish(res);
+                                } catch (e) {
+                                    callback(false, e);
+                                    return;
+                                }
+
+                                outputStream.splice_async(inputStream,
+                                                          Gio.OutputStreamSpliceFlags.CLOSE_SOURCE |
+                                                          Gio.OutputStreamSpliceFlags.CLOSE_TARGET,
+                                                          GLib.PRIORITY_DEFAULT,
+                                                          cancellable,
+                                                          Lang.bind(this,
+                                    function(object, res) {
+                                        try {
+                                            object.splice_finish(res);
+                                        } catch (e) {
+                                            callback(false, e);
+                                            return;
+                                        }
+
+                                        this.setCacheAttributes(localFile, null, Lang.bind(this,
+                                            function() {
+                                                callback(false, null);
+                                            }));
+                                    }));
+                            }));
+                    }));
+            }));
+    },
+
     load: function(passwd, cancellable, callback) {
         this._createZpjEntry(cancellable, Lang.bind(this,
             function(entry, service, exception) {


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