cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [1/2] git commit: CB-5532 WP8. Add binary data support to FileWriter
Date Tue, 03 Dec 2013 20:07:40 GMT
Updated Branches:
  refs/heads/dev e0f59bd37 -> 86f3446ae


CB-5532 WP8. Add binary data support to FileWriter


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

Branch: refs/heads/dev
Commit: ef636d93cba502a0881bd22abe744d0b9540424c
Parents: cfdb4ed
Author: sgrebnov <sergei.grebnov@gmail.com>
Authored: Tue Dec 3 14:47:32 2013 +0400
Committer: sgrebnov <sergei.grebnov@gmail.com>
Committed: Tue Dec 3 14:47:32 2013 +0400

----------------------------------------------------------------------
 src/wp/File.cs    | 7 +++++--
 www/FileWriter.js | 6 +++++-
 2 files changed, 10 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/ef636d93/src/wp/File.cs
----------------------------------------------------------------------
diff --git a/src/wp/File.cs b/src/wp/File.cs
index b0534f0..c1ac8a9 100644
--- a/src/wp/File.cs
+++ b/src/wp/File.cs
@@ -799,6 +799,9 @@ namespace WPCordovaClassLib.Cordova.Commands
                     return;
                 }
 
+                char[] dataToWrite = isBinary ? JSON.JsonHelper.Deserialize<char[]>(data)
:
+                    data.ToCharArray();
+
                 using (IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication())
                 {
                     // create the file if not exists
@@ -817,12 +820,12 @@ namespace WPCordovaClassLib.Cordova.Commands
                         using (BinaryWriter writer = new BinaryWriter(stream))
                         {
                             writer.Seek(0, SeekOrigin.End);
-                            writer.Write(data.ToCharArray());
+                            writer.Write(dataToWrite);
                         }
                     }
                 }
 
-                DispatchCommandResult(new PluginResult(PluginResult.Status.OK, data.Length),
callbackId);
+                DispatchCommandResult(new PluginResult(PluginResult.Status.OK, dataToWrite.Length),
callbackId);
             }
             catch (Exception ex)
             {

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/ef636d93/www/FileWriter.js
----------------------------------------------------------------------
diff --git a/www/FileWriter.js b/www/FileWriter.js
index 44d7a32..70b5ebd 100644
--- a/www/FileWriter.js
+++ b/www/FileWriter.js
@@ -118,7 +118,11 @@ FileWriter.prototype.write = function(data) {
 
     // Mark data type for safer transport over the binary bridge
     isBinary = supportsBinary && (data instanceof ArrayBuffer);
-
+    if (isBinary) {
+        // create a plain array, using the keys from the Uint8Array view so that we can serialize
it
+        data = Array.apply(null, new Uint8Array(data));
+    }
+    
     // Throw an exception if we are already writing a file
     if (this.readyState === FileWriter.WRITING) {
         throw new FileError(FileError.INVALID_STATE_ERR);


Mime
View raw message