Showing
6 changed files
with
74 additions
and
9 deletions
| @@ -22,7 +22,7 @@ | @@ -22,7 +22,7 @@ | ||
| 22 | + (id)compressor; | 22 | + (id)compressor; |
| 23 | 23 | ||
| 24 | // Compress the passed chunk of data | 24 | // Compress the passed chunk of data |
| 25 | -- (NSData *)compressBytes:(Bytef *)bytes length:(NSInteger)length error:(NSError **)err; | 25 | +- (NSData *)compressBytes:(Bytef *)bytes length:(NSUInteger)length error:(NSError **)err; |
| 26 | 26 | ||
| 27 | // Convenience method - pass it some data, and you'll get deflated data back | 27 | // Convenience method - pass it some data, and you'll get deflated data back |
| 28 | + (NSData *)compressData:(NSData*)uncompressedData error:(NSError **)err; | 28 | + (NSData *)compressData:(NSData*)uncompressedData error:(NSError **)err; |
| @@ -66,7 +66,7 @@ | @@ -66,7 +66,7 @@ | ||
| 66 | return nil; | 66 | return nil; |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | -- (NSData *)compressBytes:(Bytef *)bytes length:(NSInteger)length error:(NSError **)err | 69 | +- (NSData *)compressBytes:(Bytef *)bytes length:(NSUInteger)length error:(NSError **)err |
| 70 | { | 70 | { |
| 71 | if (length == 0) return nil; | 71 | if (length == 0) return nil; |
| 72 | 72 | ||
| @@ -78,7 +78,7 @@ | @@ -78,7 +78,7 @@ | ||
| 78 | int status; | 78 | int status; |
| 79 | 79 | ||
| 80 | zStream.next_in = bytes; | 80 | zStream.next_in = bytes; |
| 81 | - zStream.avail_in = length; | 81 | + zStream.avail_in = (unsigned int)length; |
| 82 | zStream.avail_out = 0; | 82 | zStream.avail_out = 0; |
| 83 | NSError *theError = nil; | 83 | NSError *theError = nil; |
| 84 | 84 | ||
| @@ -151,7 +151,7 @@ | @@ -151,7 +151,7 @@ | ||
| 151 | 151 | ||
| 152 | UInt8 inputData[DATA_CHUNK_SIZE]; | 152 | UInt8 inputData[DATA_CHUNK_SIZE]; |
| 153 | NSData *outputData; | 153 | NSData *outputData; |
| 154 | - int readLength; | 154 | + NSInteger readLength; |
| 155 | NSError *theError = nil; | 155 | NSError *theError = nil; |
| 156 | 156 | ||
| 157 | ASIDataCompressor *compressor = [ASIDataCompressor compressor]; | 157 | ASIDataCompressor *compressor = [ASIDataCompressor compressor]; |
| @@ -22,7 +22,7 @@ | @@ -22,7 +22,7 @@ | ||
| 22 | + (id)decompressor; | 22 | + (id)decompressor; |
| 23 | 23 | ||
| 24 | // Uncompress the passed chunk of data | 24 | // Uncompress the passed chunk of data |
| 25 | -- (NSData *)uncompressBytes:(Bytef *)bytes length:(NSInteger)length error:(NSError **)err; | 25 | +- (NSData *)uncompressBytes:(Bytef *)bytes length:(NSUInteger)length error:(NSError **)err; |
| 26 | 26 | ||
| 27 | // Convenience method - pass it some deflated data, and you'll get inflated data back | 27 | // Convenience method - pass it some deflated data, and you'll get inflated data back |
| 28 | + (NSData *)uncompressData:(NSData*)compressedData error:(NSError **)err; | 28 | + (NSData *)uncompressData:(NSData*)compressedData error:(NSError **)err; |
| @@ -65,7 +65,7 @@ | @@ -65,7 +65,7 @@ | ||
| 65 | return nil; | 65 | return nil; |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | -- (NSData *)uncompressBytes:(Bytef *)bytes length:(NSInteger)length error:(NSError **)err | 68 | +- (NSData *)uncompressBytes:(Bytef *)bytes length:(NSUInteger)length error:(NSError **)err |
| 69 | { | 69 | { |
| 70 | if (length == 0) return nil; | 70 | if (length == 0) return nil; |
| 71 | 71 | ||
| @@ -75,7 +75,7 @@ | @@ -75,7 +75,7 @@ | ||
| 75 | int status; | 75 | int status; |
| 76 | 76 | ||
| 77 | zStream.next_in = bytes; | 77 | zStream.next_in = bytes; |
| 78 | - zStream.avail_in = length; | 78 | + zStream.avail_in = (unsigned int)length; |
| 79 | zStream.avail_out = 0; | 79 | zStream.avail_out = 0; |
| 80 | NSError *theError = nil; | 80 | NSError *theError = nil; |
| 81 | 81 | ||
| @@ -149,7 +149,7 @@ | @@ -149,7 +149,7 @@ | ||
| 149 | 149 | ||
| 150 | UInt8 inputData[DATA_CHUNK_SIZE]; | 150 | UInt8 inputData[DATA_CHUNK_SIZE]; |
| 151 | NSData *outputData; | 151 | NSData *outputData; |
| 152 | - int readLength; | 152 | + NSInteger readLength; |
| 153 | NSError *theError = nil; | 153 | NSError *theError = nil; |
| 154 | 154 | ||
| 155 | ASIDataDecompressor *decompressor = [ASIDataDecompressor decompressor]; | 155 | ASIDataDecompressor *decompressor = [ASIDataDecompressor decompressor]; |
| @@ -24,7 +24,7 @@ | @@ -24,7 +24,7 @@ | ||
| 24 | #import "ASIDataCompressor.h" | 24 | #import "ASIDataCompressor.h" |
| 25 | 25 | ||
| 26 | // Automatically set on build | 26 | // Automatically set on build |
| 27 | -NSString *ASIHTTPRequestVersion = @"v1.7-43 2010-08-17"; | 27 | +NSString *ASIHTTPRequestVersion = @"v1.7-44 2010-08-18"; |
| 28 | 28 | ||
| 29 | NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; | 29 | NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; |
| 30 | 30 |
| @@ -667,6 +667,71 @@ | @@ -667,6 +667,71 @@ | ||
| 667 | GHAssertTrue(success,@"Failed to download data to a file"); | 667 | GHAssertTrue(success,@"Failed to download data to a file"); |
| 668 | } | 668 | } |
| 669 | 669 | ||
| 670 | +- (void)request:(ASIHTTPRequest *)request didGetMoreData:(NSData *)data | ||
| 671 | +{ | ||
| 672 | + [[self responseData] appendData:data]; | ||
| 673 | +} | ||
| 674 | + | ||
| 675 | +- (void)downloadFinished:(ASIHTTPRequest *)request | ||
| 676 | +{ | ||
| 677 | + finished = YES; | ||
| 678 | +} | ||
| 679 | + | ||
| 680 | +- (void)testCompressedResponseDelegateDataHandling | ||
| 681 | +{ | ||
| 682 | + finished = NO; | ||
| 683 | + [self setResponseData:[NSMutableData data]]; | ||
| 684 | + | ||
| 685 | + NSURL *url = [[[NSURL alloc] initWithString:@"http://asi/ASIHTTPRequest/tests/the_hound_of_the_baskervilles.text"] autorelease]; | ||
| 686 | + | ||
| 687 | + ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | ||
| 688 | + [request startSynchronous]; | ||
| 689 | + | ||
| 690 | + NSString *response = [request responseString]; | ||
| 691 | + | ||
| 692 | + // Now download again, using the delegate to handle the data | ||
| 693 | + request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | ||
| 694 | + [request setDelegate:self]; | ||
| 695 | + [request setDidReceiveDataSelector:@selector(request:didGetMoreData:)]; | ||
| 696 | + [request setDidFinishSelector:@selector(downloadFinished:)]; | ||
| 697 | + [request setShouldWaitToInflateCompressedResponses:NO]; | ||
| 698 | + [request startSynchronous]; | ||
| 699 | + | ||
| 700 | + while (!finished) { | ||
| 701 | + sleep(1); | ||
| 702 | + } | ||
| 703 | + | ||
| 704 | + NSString *delegateResponse = [[[NSString alloc] initWithBytes:[responseData bytes] length:[responseData length] encoding:[request responseEncoding]] autorelease]; | ||
| 705 | + BOOL success = [delegateResponse isEqualToString:response]; | ||
| 706 | + GHAssertTrue(success,@"Failed to correctly download the response using a delegate"); | ||
| 707 | + | ||
| 708 | + // Test again without compression | ||
| 709 | + finished = NO; | ||
| 710 | + [self setResponseData:[NSMutableData data]]; | ||
| 711 | + | ||
| 712 | + request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | ||
| 713 | + [request setAllowCompressedResponse:NO]; | ||
| 714 | + [request startSynchronous]; | ||
| 715 | + | ||
| 716 | + response = [request responseString]; | ||
| 717 | + | ||
| 718 | + // Now download again, using the delegate to handle the data | ||
| 719 | + request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | ||
| 720 | + [request setDelegate:self]; | ||
| 721 | + [request setDidReceiveDataSelector:@selector(request:didGetMoreData:)]; | ||
| 722 | + [request setDidFinishSelector:@selector(downloadFinished:)]; | ||
| 723 | + [request setAllowCompressedResponse:NO]; | ||
| 724 | + [request startSynchronous]; | ||
| 725 | + | ||
| 726 | + while (!finished) { | ||
| 727 | + sleep(1); | ||
| 728 | + } | ||
| 729 | + | ||
| 730 | + delegateResponse = [[[NSString alloc] initWithBytes:[responseData bytes] length:[responseData length] encoding:[request responseEncoding]] autorelease]; | ||
| 731 | + success = [delegateResponse isEqualToString:response]; | ||
| 732 | + GHAssertTrue(success,@"Failed to correctly download the response using a delegate"); | ||
| 733 | +} | ||
| 734 | + | ||
| 670 | 735 | ||
| 671 | - (void)testDownloadProgress | 736 | - (void)testDownloadProgress |
| 672 | { | 737 | { |
-
Please register or login to post a comment