You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ia...@apache.org on 2013/06/12 19:36:13 UTC
ios commit: [CB-2406] Add ArrayBuffer support to FileWriter.write
Updated Branches:
refs/heads/master 835abd8fe -> 3b178aad5
[CB-2406] Add ArrayBuffer support to FileWriter.write
Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/3b178aad
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/3b178aad
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/3b178aad
Branch: refs/heads/master
Commit: 3b178aad50b982eb1f4581f099930fd4b0e9bcdb
Parents: 835abd8
Author: Ian Clelland <ic...@chromium.org>
Authored: Tue Jun 11 13:56:42 2013 -0400
Committer: Ian Clelland <ic...@chromium.org>
Committed: Wed Jun 12 08:12:07 2013 -0400
----------------------------------------------------------------------
CordovaLib/Classes/CDVFile.h | 3 ++-
CordovaLib/Classes/CDVFile.m | 22 +++++++++++++++++-----
2 files changed, 19 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/3b178aad/CordovaLib/Classes/CDVFile.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVFile.h b/CordovaLib/Classes/CDVFile.h
index eaf8cbe..017b066 100644
--- a/CordovaLib/Classes/CDVFile.h
+++ b/CordovaLib/Classes/CDVFile.h
@@ -90,7 +90,8 @@ extern NSString* const kCDVAssetsLibraryPrefix;
// - (BOOL) fileExists:(NSString*)fileName;
// - (BOOL) directoryExists:(NSString*)dirName;
-- (void)writeToFile:(NSString*)fileName withData:(NSString*)data append:(BOOL)shouldAppend callback:(NSString*)callbackId;
+- (void)writeToFile:(NSString*)fileName withData:(NSData*)data append:(BOOL)shouldAppend callback:(NSString*)callbackId;
+- (void)writeToFile:(NSString*)fileName withString:(NSString*)data encoding:(NSStringEncoding)encoding append:(BOOL)shouldAppend callback:(NSString*)callbackId;
- (unsigned long long)truncateFile:(NSString*)filePath atPosition:(unsigned long long)pos;
@property (nonatomic, strong) NSString* appDocsPath;
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/3b178aad/CordovaLib/Classes/CDVFile.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVFile.m b/CordovaLib/Classes/CDVFile.m
index 10908ce..9487dd4 100644
--- a/CordovaLib/Classes/CDVFile.m
+++ b/CordovaLib/Classes/CDVFile.m
@@ -1303,7 +1303,7 @@ NSString* const kCDVAssetsLibraryPrefix = @"assets-library://";
* IN:
* NSArray* arguments
* 0 - NSString* file path to write to
- * 1 - NSString* data to write
+ * 1 - NSString* or NSData* data to write
* 2 - NSNumber* position to begin writing
*/
- (void)write:(CDVInvokedUrlCommand*)command
@@ -1313,7 +1313,7 @@ NSString* const kCDVAssetsLibraryPrefix = @"assets-library://";
// arguments
NSString* argPath = [arguments objectAtIndex:0];
- NSString* argData = [arguments objectAtIndex:1];
+ id argData = [arguments objectAtIndex:1];
unsigned long long pos = (unsigned long long)[[arguments objectAtIndex:2] longLongValue];
// text can't be written into assets-library files
@@ -1327,15 +1327,22 @@ NSString* const kCDVAssetsLibraryPrefix = @"assets-library://";
[self truncateFile:fullPath atPosition:pos];
- [self writeToFile:fullPath withData:argData append:YES callback:callbackId];
+ if ([argData isKindOfClass:[NSString class]]) {
+ [self writeToFile:fullPath withString:argData encoding:NSUTF8StringEncoding append:YES callback:callbackId];
+ } else if ([argData isKindOfClass:[NSData class]]) {
+ [self writeToFile:fullPath withData:argData append:YES callback:callbackId];
+ } else {
+ CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Invalid parameter type"];
+ [self.commandDelegate sendPluginResult:result callbackId:callbackId];
+ }
+
}
-- (void)writeToFile:(NSString*)filePath withData:(NSString*)data append:(BOOL)shouldAppend callback:(NSString*)callbackId
+- (void)writeToFile:(NSString*)filePath withData:(NSData*)encData append:(BOOL)shouldAppend callback:(NSString*)callbackId
{
CDVPluginResult* result = nil;
CDVFileError errCode = INVALID_MODIFICATION_ERR;
int bytesWritten = 0;
- NSData* encData = [data dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
if (filePath) {
NSOutputStream* fileStream = [NSOutputStream outputStreamToFileAtPath:filePath append:shouldAppend];
@@ -1365,6 +1372,11 @@ NSString* const kCDVAssetsLibraryPrefix = @"assets-library://";
[self.commandDelegate sendPluginResult:result callbackId:callbackId];
}
+- (void)writeToFile:(NSString*)filePath withString:(NSString*)stringData encoding:(NSStringEncoding)encoding append:(BOOL)shouldAppend callback:(NSString*)callbackId
+{
+ [self writeToFile:filePath withData:[stringData dataUsingEncoding:encoding allowLossyConversion:YES] append:shouldAppend callback:callbackId];
+}
+
- (void)testFileExists:(CDVInvokedUrlCommand*)command
{
// arguments