Repository: cordova-plugin-file
Updated Branches:
  refs/heads/master 1e9587ca2 -> 055e7e0bd


Fix function write for big files on windows 8


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

Branch: refs/heads/master
Commit: f9812f04ce42080002cc25184284d0741999d267
Parents: e35c794
Author: Florian BERTON <[email protected]>
Authored: Fri Jun 20 19:22:16 2014 +0200
Committer: SomaticIT <[email protected]>
Committed: Mon Sep 29 17:42:37 2014 +0200

----------------------------------------------------------------------
 src/windows8/FileProxy.js | 69 +++++++++++++++++++++++++++++++-----------
 www/FileWriter.js         |  4 ++-
 2 files changed, 54 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/f9812f04/src/windows8/FileProxy.js
----------------------------------------------------------------------
diff --git a/src/windows8/FileProxy.js b/src/windows8/FileProxy.js
index 25fdee0..08ba1e5 100644
--- a/src/windows8/FileProxy.js
+++ b/src/windows8/FileProxy.js
@@ -140,7 +140,7 @@ module.exports = {
             enc = args[1],
             startPos = args[2],
             endPos = args[3];
-        
+
         var encoding = Windows.Storage.Streams.UnicodeEncoding.utf8;
         if (enc == 'Utf16LE' || enc == 'utf16LE') {
             encoding = Windows.Storage.Streams.UnicodeEncoding.utf16LE;
@@ -423,7 +423,7 @@ module.exports = {
         completePath = completePath.replace(/\\\\\\/g, '/').replace(/\\\\/g, 
'\\');
 
         var fileName = completePath.substring(completePath.lastIndexOf('\\'));
-        
+
         //final adjustment
         fullPath = completePath.substring(0, completePath.lastIndexOf('\\'));
         path = fileName.replace(/\\/g, '');
@@ -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"]
@@ -936,7 +969,7 @@ module.exports = {
             }
         );
     }
-    
+
 
 };
 

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/f9812f04/www/FileWriter.js
----------------------------------------------------------------------
diff --git a/www/FileWriter.js b/www/FileWriter.js
index 786e994..68315fd 100644
--- a/www/FileWriter.js
+++ b/www/FileWriter.js
@@ -100,9 +100,11 @@ FileWriter.prototype.write = function(data) {
     var that=this;
     var supportsBinary = (typeof window.Blob !== 'undefined' && typeof 
window.ArrayBuffer !== 'undefined');
     var isBinary;
+    var isWin8 = cordova.platformId === "windows8" || cordova.platformId === 
"windows";
 
     // Check to see if the incoming data is a blob
-    if (data instanceof File || (supportsBinary && data instanceof Blob)) {
+    if ((!isWin8 || !(data instanceof Blob || data instanceof File)) && // 
ignore if Windows 8
+        (data instanceof File || (supportsBinary && data instanceof Blob))) {
         var fileReader = new FileReader();
         fileReader.onload = function() {
             // Call this method again, with the arraybuffer as argument


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to