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
[2/2] ios commit: Add slice() support to readAsDataURL.
Updated Branches:
refs/heads/master 330c7c39f -> 4d948963e
Add slice() support to readAsDataURL.
Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/4d948963
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/4d948963
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/4d948963
Branch: refs/heads/master
Commit: 4d948963e036464dc70c2e78d1ebe14f060055ee
Parents: edaf1c7
Author: Braden Shepherdson <br...@chromium.org>
Authored: Mon Jan 7 16:18:28 2013 -0500
Committer: Braden Shepherdson <br...@chromium.org>
Committed: Mon Jan 7 16:18:28 2013 -0500
----------------------------------------------------------------------
CordovaLib/Classes/CDVFile.m | 22 ++++++++++++++++++++--
1 files changed, 20 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/4d948963/CordovaLib/Classes/CDVFile.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVFile.m b/CordovaLib/Classes/CDVFile.m
index 4e36e78..bff91f9 100644
--- a/CordovaLib/Classes/CDVFile.m
+++ b/CordovaLib/Classes/CDVFile.m
@@ -921,7 +921,7 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
start = [[command.arguments objectAtIndex:2] integerValue];
}
if ([command.arguments count] >= 4) {
- end = [[command.argument objectAtIndex:3] integerValue];
+ end = [[command.arguments objectAtIndex:3] integerValue];
}
// NSString* encoding = [command.arguments objectAtIndex:2]; // not currently used
@@ -970,6 +970,14 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
{
// arguments
NSString* argPath = [command.arguments objectAtIndex:0];
+ NSInteger start = 0;
+ NSInteger end = -1;
+ if ([command.arguments count] >= 2) {
+ start = [[command.arguments objectAtIndex:1] integerValue];
+ }
+ if ([command.arguments count] >= 3) {
+ end = [[command.arguments objectAtIndex:2] integerValue];
+ }
CDVFileError errCode = ABORT_ERR;
CDVPluginResult* result = nil;
@@ -983,7 +991,17 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
errCode = ENCODING_ERR;
} else {
NSFileHandle* file = [NSFileHandle fileHandleForReadingAtPath:argPath];
- 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];
if (readData) {
NSString* output = [NSString stringWithFormat:@"data:%@;base64,%@", mimeType, [readData base64EncodedString]];