Skip to content

Commit ef636d9

Browse files
committed
CB-5532 WP8. Add binary data support to FileWriter
1 parent cfdb4ed commit ef636d9

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/wp/File.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,9 @@ public void write(string options)
799799
return;
800800
}
801801

802+
char[] dataToWrite = isBinary ? JSON.JsonHelper.Deserialize<char[]>(data) :
803+
data.ToCharArray();
804+
802805
using (IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication())
803806
{
804807
// create the file if not exists
@@ -817,12 +820,12 @@ public void write(string options)
817820
using (BinaryWriter writer = new BinaryWriter(stream))
818821
{
819822
writer.Seek(0, SeekOrigin.End);
820-
writer.Write(data.ToCharArray());
823+
writer.Write(dataToWrite);
821824
}
822825
}
823826
}
824827

825-
DispatchCommandResult(new PluginResult(PluginResult.Status.OK, data.Length), callbackId);
828+
DispatchCommandResult(new PluginResult(PluginResult.Status.OK, dataToWrite.Length), callbackId);
826829
}
827830
catch (Exception ex)
828831
{

www/FileWriter.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@ FileWriter.prototype.write = function(data) {
118118

119119
// Mark data type for safer transport over the binary bridge
120120
isBinary = supportsBinary && (data instanceof ArrayBuffer);
121-
121+
if (isBinary) {
122+
// create a plain array, using the keys from the Uint8Array view so that we can serialize it
123+
data = Array.apply(null, new Uint8Array(data));
124+
}
125+
122126
// Throw an exception if we are already writing a file
123127
if (this.readyState === FileWriter.WRITING) {
124128
throw new FileError(FileError.INVALID_STATE_ERR);

0 commit comments

Comments
 (0)