cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From an-s...@apache.org
Subject [1/2] git commit: CB-6994 Fixes result, returned by proxy's write method
Date Fri, 10 Oct 2014 08:47:52 GMT
Repository: cordova-plugin-file
Updated Branches:
  refs/heads/master 813356851 -> ab9ff4d8d


CB-6994 Fixes result, returned by proxy's write method

+ Refactors writeBlobAsync function
+ Fixes proxy's remove method failure when trying to delete non-existent file


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/cfcb74ca
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/cfcb74ca
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/cfcb74ca

Branch: refs/heads/master
Commit: cfcb74ca972134eb361fc89c7b419ad912b70972
Parents: 8133568
Author: Vladimir Kotikov <v-vlkoti@microsoft.com>
Authored: Fri Oct 10 12:39:16 2014 +0400
Committer: Vladimir Kotikov <v-vlkoti@microsoft.com>
Committed: Fri Oct 10 12:45:42 2014 +0400

----------------------------------------------------------------------
 src/windows/FileProxy.js | 54 +++++++++++++++----------------------------
 1 file changed, 19 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/cfcb74ca/src/windows/FileProxy.js
----------------------------------------------------------------------
diff --git a/src/windows/FileProxy.js b/src/windows/FileProxy.js
index 5d1f7ca..9910c54 100644
--- a/src/windows/FileProxy.js
+++ b/src/windows/FileProxy.js
@@ -64,35 +64,21 @@ var getFileFromPathAsync = Windows.Storage.StorageFile.getFileFromPathAsync;
 var writeBytesAsync = Windows.Storage.FileIO.writeBytesAsync;
 var writeTextAsync = Windows.Storage.FileIO.writeTextAsync;
 var writeBlobAsync = function writeBlobAsync(storageFile, data) {
-    return new WinJS.Promise(function (resolve, reject) {
-        storageFile.openAsync(Windows.Storage.FileAccessMode.readWrite).then(
-            function (output) {
-                var input = (data.detachStream || data.msDetachStream).call(data);
-
-                // 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();
-
-                                resolve(data.length);
-                            },
-                            function () {
-                                reject(FileError.INVALID_MODIFICATION_ERR);
-                            }
-                        );
-                    },
-                    function () {
-                        reject(FileError.INVALID_MODIFICATION_ERR);
-                    }
-                );
-            },
-            function () {
-                reject(FileError.INVALID_MODIFICATION_ERR);
-            }
-        );
+    return storageFile.openAsync(Windows.Storage.FileAccessMode.readWrite)
+    .then(function (output) {
+        var dataSize = data.size;
+        var input = (data.detachStream || data.msDetachStream).call(data);
+
+        // Copy the stream from the blob to the File stream 
+        return Windows.Storage.Streams.RandomAccessStream.copyAsync(input, output)
+        .then(function () {
+            return output.flushAsync().then(function () {
+                input.close();
+                output.close();
+
+                return dataSize;
+            });
+        });
     });
 };
 
@@ -363,12 +349,9 @@ module.exports = {
         var fullPath = cordovaPathToNative(args[0]);
 
         getFileFromPathAsync(fullPath).then(
-            function (sFile) {
-                getFileFromPathAsync(fullPath).done(function (storageFile) {
+            function (storageFile) {
                     storageFile.deleteAsync().done(win, function () {
                         fail(FileError.INVALID_MODIFICATION_ERR);
-
-                    });
                 });
             },
             function () {
@@ -587,8 +570,9 @@ module.exports = {
                 storageFolder.createFileAsync(file, Windows.Storage.CreationCollisionOption.openIfExists).done(
                     function (storageFile) {
                         writePromise(storageFile, data).done(
-                            function () {
-                                win(data.length);
+                            function (bytesWritten) {
+                                var written = bytesWritten || data.length;
+                                win(written);
                             },
                             function () {
                                 fail(FileError.INVALID_MODIFICATION_ERR);


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


Mime
View raw message