You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2015/02/10 02:37:01 UTC
[1/2] cordova-plugin-file git commit: Added nativeURL property to
FileEntry, implemented readAsArrayBuffer and readAsBinaryString
Repository: cordova-plugin-file
Updated Branches:
refs/heads/master 638d8a21a -> 5cfe7a05b
Added nativeURL property to FileEntry, implemented readAsArrayBuffer and readAsBinaryString
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/6f630b4b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/6f630b4b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/6f630b4b
Branch: refs/heads/master
Commit: 6f630b4b19271a98ea6e896358c0386283104c43
Parents: 638d8a2
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Mon Feb 9 17:27:29 2015 -0800
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Mon Feb 9 17:27:29 2015 -0800
----------------------------------------------------------------------
src/wp/File.cs | 141 ++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 109 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/6f630b4b/src/wp/File.cs
----------------------------------------------------------------------
diff --git a/src/wp/File.cs b/src/wp/File.cs
index c383372..1ada92d 100644
--- a/src/wp/File.cs
+++ b/src/wp/File.cs
@@ -326,6 +326,26 @@ namespace WPCordovaClassLib.Cordova.Commands
[DataMember(Name = "fullPath")]
public string FullPath { get; set; }
+ /// <summary>
+ /// URI encoded fullpath
+ /// </summary>
+ [DataMember(Name = "nativeURL")]
+ public string NativeURL
+ {
+ set { }
+ get
+ {
+ string escaped = Uri.EscapeUriString(this.FullPath);
+ escaped = escaped.Replace("//", "/");
+ if (escaped.StartsWith("/"))
+ {
+ escaped = escaped.Insert(0, "/");
+ }
+ return escaped;
+ }
+
+ }
+
public bool IsResource { get; set; }
public static FileEntry GetEntry(string filePath, bool bIsRes=false)
@@ -623,6 +643,39 @@ namespace WPCordovaClassLib.Cordova.Commands
}
}
+ private byte[] readFileBytes(string filePath,int startPos,int endPos, IsolatedStorageFile isoFile)
+ {
+ byte[] buffer;
+ using (IsolatedStorageFileStream reader = isoFile.OpenFile(filePath, FileMode.Open, FileAccess.Read))
+ {
+ if (startPos < 0)
+ {
+ startPos = Math.Max((int)reader.Length + startPos, 0);
+ }
+ else if (startPos > 0)
+ {
+ startPos = Math.Min((int)reader.Length, startPos);
+ }
+
+ if (endPos > 0)
+ {
+ endPos = Math.Min((int)reader.Length, endPos);
+ }
+ else if (endPos < 0)
+ {
+ endPos = Math.Max(endPos + (int)reader.Length, 0);
+ }
+
+
+ buffer = new byte[endPos - startPos];
+
+ reader.Seek(startPos, SeekOrigin.Begin);
+ reader.Read(buffer, 0, buffer.Length);
+ }
+
+ return buffer;
+ }
+
public void readAsArrayBuffer(string options)
{
string[] optStrings = getOptionStrings(options);
@@ -630,7 +683,30 @@ namespace WPCordovaClassLib.Cordova.Commands
int startPos = int.Parse(optStrings[1]);
int endPos = int.Parse(optStrings[2]);
string callbackId = optStrings[3];
- DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR), callbackId);
+
+ try
+ {
+ byte[] buffer;
+
+ using (IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication())
+ {
+ if (!isoFile.FileExists(filePath))
+ {
+ readResourceAsText(options);
+ return;
+ }
+ buffer = readFileBytes(filePath, startPos, endPos, isoFile);
+ }
+
+ DispatchCommandResult(new PluginResult(PluginResult.Status.OK, buffer), callbackId);
+ }
+ catch (Exception ex)
+ {
+ if (!this.HandleException(ex, callbackId))
+ {
+ DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, NOT_READABLE_ERR), callbackId);
+ }
+ }
}
public void readAsBinaryString(string options)
@@ -640,7 +716,35 @@ namespace WPCordovaClassLib.Cordova.Commands
int startPos = int.Parse(optStrings[1]);
int endPos = int.Parse(optStrings[2]);
string callbackId = optStrings[3];
- DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR), callbackId);
+ //DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR), callbackId);
+
+ try
+ {
+ string result;
+
+ using (IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication())
+ {
+ if (!isoFile.FileExists(filePath))
+ {
+ readResourceAsText(options);
+ return;
+ }
+
+ byte[] buffer = readFileBytes(filePath, startPos, endPos, isoFile);
+
+ result = System.Text.Encoding.UTF8.GetString(buffer, 0, buffer.Length);
+
+ }
+
+ DispatchCommandResult(new PluginResult(PluginResult.Status.OK, result), callbackId);
+ }
+ catch (Exception ex)
+ {
+ if (!this.HandleException(ex, callbackId))
+ {
+ DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, NOT_READABLE_ERR), callbackId);
+ }
+ }
}
public void readAsText(string options)
@@ -665,35 +769,8 @@ namespace WPCordovaClassLib.Cordova.Commands
}
Encoding encoding = Encoding.GetEncoding(encStr);
- using (IsolatedStorageFileStream reader = isoFile.OpenFile(filePath, FileMode.Open, FileAccess.Read))
- {
- if (startPos < 0)
- {
- startPos = Math.Max((int)reader.Length + startPos, 0);
- }
- else if (startPos > 0)
- {
- startPos = Math.Min((int)reader.Length, startPos);
- }
-
- if (endPos > 0)
- {
- endPos = Math.Min((int)reader.Length, endPos);
- }
- else if (endPos < 0)
- {
- endPos = Math.Max(endPos + (int)reader.Length, 0);
- }
-
-
- var buffer = new byte[endPos - startPos];
-
- reader.Seek(startPos, SeekOrigin.Begin);
- reader.Read(buffer, 0, buffer.Length);
-
- text = encoding.GetString(buffer, 0, buffer.Length);
-
- }
+ byte[] buffer = this.readFileBytes(filePath, startPos, endPos, isoFile);
+ text = encoding.GetString(buffer, 0, buffer.Length);
}
DispatchCommandResult(new PluginResult(PluginResult.Status.OK, text), callbackId);
@@ -812,7 +889,7 @@ namespace WPCordovaClassLib.Cordova.Commands
}
byte[] dataToWrite = isBinary ? JSON.JsonHelper.Deserialize<byte[]>(data) :
- System.Text.Encoding.UTF8.GetBytes(data);
+ System.Text.Encoding.UTF8.GetBytes(data);
using (IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication())
{
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[2/2] cordova-plugin-file git commit: Code cleanup, whitespace
Posted by pu...@apache.org.
Code cleanup, whitespace
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/5cfe7a05
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/5cfe7a05
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/5cfe7a05
Branch: refs/heads/master
Commit: 5cfe7a05b50c4139c42c0f7d8f4ce0abaa5c3eb1
Parents: 6f630b4
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Mon Feb 9 17:34:39 2015 -0800
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Mon Feb 9 17:34:39 2015 -0800
----------------------------------------------------------------------
src/wp/File.cs | 7 -------
1 file changed, 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/5cfe7a05/src/wp/File.cs
----------------------------------------------------------------------
diff --git a/src/wp/File.cs b/src/wp/File.cs
index 1ada92d..eff802f 100644
--- a/src/wp/File.cs
+++ b/src/wp/File.cs
@@ -343,7 +343,6 @@ namespace WPCordovaClassLib.Cordova.Commands
}
return escaped;
}
-
}
public bool IsResource { get; set; }
@@ -656,7 +655,6 @@ namespace WPCordovaClassLib.Cordova.Commands
{
startPos = Math.Min((int)reader.Length, startPos);
}
-
if (endPos > 0)
{
endPos = Math.Min((int)reader.Length, endPos);
@@ -666,9 +664,7 @@ namespace WPCordovaClassLib.Cordova.Commands
endPos = Math.Max(endPos + (int)reader.Length, 0);
}
-
buffer = new byte[endPos - startPos];
-
reader.Seek(startPos, SeekOrigin.Begin);
reader.Read(buffer, 0, buffer.Length);
}
@@ -716,7 +712,6 @@ namespace WPCordovaClassLib.Cordova.Commands
int startPos = int.Parse(optStrings[1]);
int endPos = int.Parse(optStrings[2]);
string callbackId = optStrings[3];
- //DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR), callbackId);
try
{
@@ -731,7 +726,6 @@ namespace WPCordovaClassLib.Cordova.Commands
}
byte[] buffer = readFileBytes(filePath, startPos, endPos, isoFile);
-
result = System.Text.Encoding.UTF8.GetString(buffer, 0, buffer.Length);
}
@@ -772,7 +766,6 @@ namespace WPCordovaClassLib.Cordova.Commands
byte[] buffer = this.readFileBytes(filePath, startPos, endPos, isoFile);
text = encoding.GetString(buffer, 0, buffer.Length);
}
-
DispatchCommandResult(new PluginResult(PluginResult.Status.OK, text), callbackId);
}
catch (Exception ex)
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org