cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bra...@apache.org
Subject [1/2] ios commit: Add slice() support to readAsText.
Date Mon, 07 Jan 2013 23:13:01 GMT
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 <braden@chromium.org>
Authored: Mon Jan 7 16:10:34 2013 -0500
Committer: Braden Shepherdson <braden@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;


Mime
View raw message