Skip to content

Commit

Permalink
-writeData:error: variant
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeabdullah committed Jul 10, 2011
1 parent 9e0cb3d commit 90d5d87
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions CK2SFTPFileHandle.h
Expand Up @@ -27,6 +27,7 @@

- (BOOL)closeFile:(NSError **)error;

- (BOOL)writeData:(NSData *)data error:(NSError **)error;
- (NSInteger)write:(const uint8_t *)buffer maxLength:(NSUInteger)length error:(NSError **)error;
- (NSInteger)write:(const uint8_t *)buffer maxLength:(NSUInteger)length;

Expand Down
20 changes: 13 additions & 7 deletions CK2SFTPFileHandle.m
Expand Up @@ -59,6 +59,15 @@ - (void)dealloc;
}

- (void)writeData:(NSData *)data;
{
NSError *error;
if (![self writeData:data error:&error])
{
[NSException raise:NSFileHandleOperationException format:@"%@", [error localizedDescription]];
}
}

- (BOOL)writeData:(NSData *)data error:(NSError **)error;
{
NSUInteger offset = 0;
NSUInteger remainder = [data length];
Expand All @@ -67,17 +76,14 @@ - (void)writeData:(NSData *)data;
{
const void *bytes = [data bytes];

NSError *error;
NSInteger written = [self write:bytes+offset maxLength:remainder error:&error];

if (written < 0)
{
[NSException raise:NSFileHandleOperationException format:@"%@", [error localizedDescription]];
}
NSInteger written = [self write:bytes+offset maxLength:remainder error:error];
if (written < 0) return NO;

offset+=written;
remainder-=written;
}

return YES;
}

- (NSInteger)write:(const uint8_t *)buffer maxLength:(NSUInteger)length error:(NSError **)error;
Expand Down

0 comments on commit 90d5d87

Please sign in to comment.