Created
May 16, 2018 13:17
-
-
Save jidolstar/b166924a40c65675192ade3c3bdc3bc3 to your computer and use it in GitHub Desktop.
Http File을 보낼 때 사용.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "bsHttpFile.h" | |
#import "bsMacro.h" | |
@interface bsHttpFile(){ | |
NSMutableDictionary *_files; | |
} | |
@end | |
@implementation bsHttpFile | |
static NSMutableArray *__bsHttpFile_pool = nil; | |
+(bsHttpFile*)POP { | |
__block bsHttpFile *r; | |
@synchronized( __bsHttpFile_pool ) { | |
if( __bsHttpFile_pool == nil ) { | |
__bsHttpFile_pool = [[NSMutableArray alloc]init]; | |
} | |
if( [__bsHttpFile_pool count] > 0 ) { | |
r = [__bsHttpFile_pool lastObject]; | |
[__bsHttpFile_pool removeLastObject]; | |
} else { | |
r = [[bsHttpFile alloc] init]; | |
} | |
}; | |
return r; | |
} | |
+(void)PUT:(bsHttpFile*)file { | |
if( file == nil ) return; | |
@synchronized( __bsHttpFile_pool ) { | |
if( __bsHttpFile_pool == nil ) { | |
__bsHttpFile_pool = [[NSMutableArray alloc] init]; | |
} | |
[file clear]; | |
[__bsHttpFile_pool addObject:file]; | |
}; | |
} | |
-(void)addWithName:(NSString*)name data:(NSData*)data { | |
if( name == nil ) bsException( @"name is nil" ); | |
if( data == nil ) bsException( @"data is nil" ); | |
@synchronized( _files ) { | |
if( _files == nil ) { | |
_files = [[NSMutableDictionary alloc]init]; | |
} | |
_files[[name copy]] = data; | |
} | |
} | |
-(void)loop:(void (^)(NSString *name, NSData *data))block { | |
@synchronized( _files ) { | |
[_files enumerateKeysAndObjectsUsingBlock:^(NSString *name, NSData *data, BOOL *stop) { | |
if( block ) block( name, data ); | |
}]; | |
} | |
} | |
-(NSUInteger)count { | |
@synchronized( _files ) { | |
if( _files ) { | |
return [_files count]; | |
} | |
} | |
return 0; | |
} | |
-(void)clear { | |
@synchronized( _files ){ | |
[_files removeAllObjects]; | |
}; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment