cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sgreb...@apache.org
Subject [2/6] git commit: Synchronize changes with windows platform
Date Wed, 08 Oct 2014 16:44:12 GMT
Synchronize changes with windows platform


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/commit/68613862
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/68613862
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/68613862

Branch: refs/heads/master
Commit: 686138622d6996bb7b3fc945115156f3b38630f7
Parents: f9812f0
Author: SomaticIT <contact@somatic.fr>
Authored: Mon Sep 29 17:46:16 2014 +0200
Committer: SomaticIT <contact@somatic.fr>
Committed: Mon Sep 29 17:48:21 2014 +0200

----------------------------------------------------------------------
 src/windows/FileProxy.js | 63 ++++++++++++++++++++++++++++++++-----------
 1 file changed, 48 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/68613862/src/windows/FileProxy.js
----------------------------------------------------------------------
diff --git a/src/windows/FileProxy.js b/src/windows/FileProxy.js
index 8d36ddb..474f044 100644
--- a/src/windows/FileProxy.js
+++ b/src/windows/FileProxy.js
@@ -518,36 +518,69 @@ module.exports = {
         if (data instanceof ArrayBuffer) {
             data = Array.apply(null, new Uint8Array(data));
         }
-        
-        var writePromise = isBinary ? Windows.Storage.FileIO.writeBytesAsync : Windows.Storage.FileIO.writeTextAsync;
 
-        
         fileName = fileName.split("/").join("\\");
 
-
         // split path to folder and file name
         var path = fileName.substring(0, fileName.lastIndexOf('\\')),
             file = fileName.split('\\').pop();
-        
 
         getFolderFromPathAsync(path).done(
             function(storageFolder) {
                 storageFolder.createFileAsync(file, Windows.Storage.CreationCollisionOption.openIfExists).done(
                     function(storageFile) {
-                        writePromise(storageFile, data).
-                            done(function () {
-                                win(data.length);
-                            }, function () {
-                                fail(FileError.INVALID_MODIFICATION_ERR);
-                            });
-                    }, function() {
+                        if (data instanceof Blob || data instanceof File) {
+                            storageFile.openAsync(Windows.Storage.FileAccessMode.readWrite).done(
+                                function (output) {
+                                    var input = data.msDetachStream();
+
+                                    // Copy the stream from the blob to the File stream 
+                                    Windows.Storage.Streams.RandomAccessStream.copyAsync(input,
output).then(
+                                        function () {
+                                            output.flushAsync().done(
+                                                function () {
+                                                    input.close();
+                                                    output.close();
+
+                                                    win(data.length);
+                                                },
+                                                function () {
+                                                    fail(FileError.INVALID_MODIFICATION_ERR);
+                                                }
+                                            );
+                                        },
+                                        function () {
+                                            fail(FileError.INVALID_MODIFICATION_ERR);
+                                        }
+                                    );
+                                },
+                                function () {
+                                    fail(FileError.INVALID_MODIFICATION_ERR);
+                                }
+                            );
+                        }
+                        else {
+                            var writePromise = isBinary ? Windows.Storage.FileIO.writeBytesAsync
: Windows.Storage.FileIO.writeTextAsync;
+                            writePromise(storageFile, data).done(
+                                function () {
+                                    win(data.length);
+                                },
+                                function () {
+                                    fail(FileError.INVALID_MODIFICATION_ERR);
+                                }
+                            );
+                        }
+                    },
+                    function () {
                         fail(FileError.INVALID_MODIFICATION_ERR);
                     }
                 );
-                
-            }, function() {
+
+            },
+            function () {
                 fail(FileError.NOT_FOUND_ERR);
-            });
+            }
+        );
     },
 
     truncate: function (win, fail, args) { // ["fileName","size"]


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message