You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by br...@apache.org on 2013/01/08 00:13:01 UTC

[1/2] ios commit: Add slice() support to readAsText.

Add slice() support to readAsText.


Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/edaf1c71
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/edaf1c71
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/edaf1c71

Branch: refs/heads/master
Commit: edaf1c71a44875f49815ef9a36f4c9c5eb862be2
Parents: 330c7c3
Author: Braden Shepherdson <br...@chromium.org>
Authored: Mon Jan 7 16:10:34 2013 -0500
Committer: Braden Shepherdson <br...@chromium.org>
Committed: Mon Jan 7 16:10:34 2013 -0500

----------------------------------------------------------------------
 CordovaLib/Classes/CDVFile.m |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/edaf1c71/CordovaLib/Classes/CDVFile.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVFile.m b/CordovaLib/Classes/CDVFile.m
index 1e5d009..4e36e78 100644
--- a/CordovaLib/Classes/CDVFile.m
+++ b/CordovaLib/Classes/CDVFile.m
@@ -908,11 +908,22 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
  * NSArray* arguments
  *	0 - NSString* fullPath
  *	1 - NSString* encoding - NOT USED,  iOS reads and writes using UTF8!
+ *	2 - NSString* start - OPTIONAL, only provided when not == 0.
+ *	3 - NSString* end - OPTIONAL, only provided when not == length.
  */
 - (void)readAsText:(CDVInvokedUrlCommand*)command
 {
     // arguments
     NSString* argPath = [command.arguments objectAtIndex:0];
+    NSInteger start = 0;
+    NSInteger end = -1;
+    if ([command.arguments count] >= 3) {
+        start = [[command.arguments objectAtIndex:2] integerValue];
+    }
+    if ([command.arguments count] >= 4) {
+        end = [[command.argument objectAtIndex:3] integerValue];
+    }
+
     // NSString* encoding = [command.arguments objectAtIndex:2];   // not currently used
     CDVPluginResult* result = nil;
 
@@ -922,7 +933,16 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
         // invalid path entry
         result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsInt:NOT_FOUND_ERR];
     } else {
-        NSData* readData = [file readDataToEndOfFile];
+        if (start > 0) {
+            [file seekToFileOffset:start];
+        }
+
+        NSData* readData;
+        if (end < 0) {
+            readData = [file readDataToEndOfFile];
+        } else {
+            readData = [file readDataOfLength:(end - start)];
+        }
 
         [file closeFile];
         NSString* pNStrBuff = nil;