cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject git commit: updated ios native files
Date Tue, 18 Jun 2013 00:26:57 GMT
Updated Branches:
  refs/heads/master 4ec6570ea -> 66ab05e7a


updated ios native files


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/66ab05e7
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/66ab05e7
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/66ab05e7

Branch: refs/heads/master
Commit: 66ab05e7a1c44ee9b2b44289b8868de6dbe7ebaa
Parents: 4ec6570
Author: Steven Gill <stevengill97@gmail.com>
Authored: Mon Jun 17 17:26:31 2013 -0700
Committer: Steven Gill <stevengill97@gmail.com>
Committed: Mon Jun 17 17:26:31 2013 -0700

----------------------------------------------------------------------
 src/ios/CDVFile.h |  5 +++--
 src/ios/CDVFile.m | 32 ++++++++++++++++++++++----------
 2 files changed, 25 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/66ab05e7/src/ios/CDVFile.h
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.h b/src/ios/CDVFile.h
index eaf8cbe..54d25f0 100644
--- a/src/ios/CDVFile.h
+++ b/src/ios/CDVFile.h
@@ -18,7 +18,7 @@
  */
 
 #import <Foundation/Foundation.h>
-#import "CDVPlugin.h"
+#import <Cordova/CDVPlugin.h>
 
 enum CDVFileError {
     NO_ERROR = 0,
@@ -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-plugin-file/blob/66ab05e7/src/ios/CDVFile.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.m b/src/ios/CDVFile.m
index 10908ce..6e3368c 100644
--- a/src/ios/CDVFile.m
+++ b/src/ios/CDVFile.m
@@ -18,15 +18,15 @@
  */
 
 #import "CDVFile.h"
-#import "NSArray+Comparisons.h"
-#import "NSDictionary+Extensions.h"
-#import "CDVJSON.h"
-#import "NSData+Base64.h"
+#import <Cordova/NSArray+Comparisons.h>
+#import <Cordova/NSDictionary+Extensions.h>
+#import <Cordova/CDVJSON.h>
+#import <Cordova/NSData+Base64.h>
 #import <AssetsLibrary/ALAsset.h>
 #import <AssetsLibrary/ALAssetRepresentation.h>
 #import <AssetsLibrary/ALAssetsLibrary.h>
 #import <MobileCoreServices/MobileCoreServices.h>
-#import "CDVAvailability.h"
+#import <Cordova/CDVAvailability.h>
 #import "sys/xattr.h"
 
 extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import));
@@ -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


Mime
View raw message