cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i..@apache.org
Subject [1/2] git commit: Write file in background
Date Mon, 06 Oct 2014 21:13:46 GMT
Repository: cordova-plugin-file
Updated Branches:
  refs/heads/master 4a820172f -> 1e9587ca2


Write file in background


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

Branch: refs/heads/master
Commit: 2153d329cc97f192f5415314c2b8767df796e260
Parents: d0af821
Author: Roi Avinoam <avinoamr@gmail.com>
Authored: Fri Sep 5 16:53:28 2014 +0300
Committer: Roi Avinoam <avinoamr@gmail.com>
Committed: Fri Sep 5 16:53:28 2014 +0300

----------------------------------------------------------------------
 src/ios/CDVFile.m | 39 ++++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/2153d329/src/ios/CDVFile.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.m b/src/ios/CDVFile.m
index 0975340..3d819b4 100644
--- a/src/ios/CDVFile.m
+++ b/src/ios/CDVFile.m
@@ -949,29 +949,30 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
  */
 - (void)write:(CDVInvokedUrlCommand*)command
 {
-    NSString* callbackId = command.callbackId;
-    NSArray* arguments = command.arguments;
+    [self.commandDelegate runInBackground:^ {
+        NSString* callbackId = command.callbackId;
+        NSArray* arguments = command.arguments;
 
-    // arguments
-    CDVFilesystemURL* localURI = [self fileSystemURLforArg:command.arguments[0]];
-    id argData = [arguments objectAtIndex:1];
-    unsigned long long pos = (unsigned long long)[[arguments objectAtIndex:2] longLongValue];
+        // arguments
+        CDVFilesystemURL* localURI = [self fileSystemURLforArg:command.arguments[0]];
+        id argData = [arguments objectAtIndex:1];
+        unsigned long long pos = (unsigned long long)[[arguments objectAtIndex:2] longLongValue];
 
-    NSObject<CDVFileSystem> *fs = [self filesystemForURL:localURI];
+        NSObject<CDVFileSystem> *fs = [self filesystemForURL:localURI];
 
 
-    [fs truncateFileAtURL:localURI atPosition:pos];
-    CDVPluginResult *result;
-    if ([argData isKindOfClass:[NSString class]]) {
-        NSData *encData = [argData dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
-        result = [fs writeToFileAtURL:localURI withData:encData append:YES];
-    } else if ([argData isKindOfClass:[NSData class]]) {
-        result = [fs writeToFileAtURL:localURI withData:argData append:YES];
-    } else {
-        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Invalid
parameter type"];
-    }
-    [self.commandDelegate sendPluginResult:result callbackId:callbackId];
-
+        [fs truncateFileAtURL:localURI atPosition:pos];
+        CDVPluginResult *result;
+        if ([argData isKindOfClass:[NSString class]]) {
+            NSData *encData = [argData dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
+            result = [fs writeToFileAtURL:localURI withData:encData append:YES];
+        } else if ([argData isKindOfClass:[NSData class]]) {
+            result = [fs writeToFileAtURL:localURI withData:argData append:YES];
+        } else {
+            result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Invalid
parameter type"];
+        }
+        [self.commandDelegate sendPluginResult:result callbackId:callbackId];
+    }];
 }
 
 #pragma mark Methods for converting between URLs and paths


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message