Ben Copsey

Start work on on-the-fly inflating

Probably need to move all this gzip stuff out of ASIHTTPRequest next, it's starting to get a bit complicated
@@ -14,6 +14,7 @@ @@ -14,6 +14,7 @@
14 #if TARGET_OS_IPHONE 14 #if TARGET_OS_IPHONE
15 #import <CFNetwork/CFNetwork.h> 15 #import <CFNetwork/CFNetwork.h>
16 #endif 16 #endif
  17 +#import <zlib.h>
17 #import <stdio.h> 18 #import <stdio.h>
18 #import "ASIHTTPRequestConfig.h" 19 #import "ASIHTTPRequestConfig.h"
19 #import "ASIHTTPRequestDelegate.h" 20 #import "ASIHTTPRequestDelegate.h"
@@ -145,12 +146,17 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount; @@ -145,12 +146,17 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount;
145 // If downloadDestinationPath is not set, download data will be stored in memory 146 // If downloadDestinationPath is not set, download data will be stored in memory
146 NSString *downloadDestinationPath; 147 NSString *downloadDestinationPath;
147 148
148 - //The location that files will be downloaded to. Once a download is complete, files will be decompressed (if necessary) and moved to downloadDestinationPath 149 + // The location that files will be downloaded to. Once a download is complete, files will be decompressed (if necessary) and moved to downloadDestinationPath
149 NSString *temporaryFileDownloadPath; 150 NSString *temporaryFileDownloadPath;
150 151
  152 + // If
  153 + NSString *temporaryUncompressedDataDownloadPath;
  154 +
151 // Used for writing data to a file when downloadDestinationPath is set 155 // Used for writing data to a file when downloadDestinationPath is set
152 NSOutputStream *fileDownloadOutputStream; 156 NSOutputStream *fileDownloadOutputStream;
153 157
  158 + NSOutputStream *inflatedFileDownloadOutputStream;
  159 +
154 // When the request fails or completes successfully, complete will be true 160 // When the request fails or completes successfully, complete will be true
155 BOOL complete; 161 BOOL complete;
156 162
@@ -423,7 +429,13 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount; @@ -423,7 +429,13 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount;
423 429
424 // Set secondsToCache to use a custom time interval for expiring the response when it is stored in a cache 430 // Set secondsToCache to use a custom time interval for expiring the response when it is stored in a cache
425 NSTimeInterval secondsToCache; 431 NSTimeInterval secondsToCache;
  432 +
  433 + z_stream zStream;
  434 + NSMutableData *uncompressedResponseData;
  435 + int lastLen;
  436 +
426 } 437 }
  438 +- (NSData *)uncompressBytes:(void *)bytes length:(NSInteger)length error:(NSError **)err;
427 439
428 #pragma mark init / dealloc 440 #pragma mark init / dealloc
429 441
@@ -478,15 +490,7 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount; @@ -478,15 +490,7 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount;
478 // Run request in the background 490 // Run request in the background
479 - (void)startAsynchronous; 491 - (void)startAsynchronous;
480 492
481 -#pragma mark request logic  
482 -  
483 -// Call to delete the temporary file used during a file download (if it exists)  
484 -// No need to call this if the request succeeds - it is removed automatically  
485 -- (void)removeTemporaryDownloadFile;  
486 493
487 -// Call to remove the file used as the request body  
488 -// No need to call this if the request succeeds and you didn't specify postBodyFilePath manually - it is removed automatically  
489 -- (void)removePostDataFile;  
490 494
491 #pragma mark HEAD request 495 #pragma mark HEAD request
492 496
@@ -587,6 +591,25 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount; @@ -587,6 +591,25 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount;
587 - (void)handleStreamComplete; 591 - (void)handleStreamComplete;
588 - (void)handleStreamError; 592 - (void)handleStreamError;
589 593
  594 +#pragma mark cleanup
  595 +
  596 +// Cleans up temporary files. There's normally no reason to call these yourself, they are called automatically when a request completes or fails
  597 +
  598 +// Clean up the temporary file used to store the downloaded data when it comes in (if downloadDestinationPath is set)
  599 +- (BOOL)removeTemporaryDownloadFile;
  600 +
  601 +// Clean up the temporary file used to store data that is inflated (decompressed) as it comes in
  602 +- (BOOL)removeTemporaryUncompressedDownloadFile;
  603 +
  604 +// Clean up the temporary file used to store the request body (when shouldStreamPostDataFromDisk is YES)
  605 +- (BOOL)removeTemporaryUploadFile;
  606 +
  607 +// Clean up the temporary file used to store a deflated (compressed) request body when shouldStreamPostDataFromDisk is YES
  608 +- (BOOL)removeTemporaryCompressedUploadFile;
  609 +
  610 +// Remove a file on disk, returning NO and populating the passed error pointer if it fails
  611 ++ (BOOL)removeFileAtPath:(NSString *)path error:(NSError **)err;
  612 +
590 #pragma mark persistent connections 613 #pragma mark persistent connections
591 614
592 // Get the ID of the connection this request used (only really useful in tests and debugging) 615 // Get the ID of the connection this request used (only really useful in tests and debugging)
@@ -644,19 +667,19 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount; @@ -644,19 +667,19 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount;
644 #pragma mark gzip decompression 667 #pragma mark gzip decompression
645 668
646 // Uncompress gzipped data with zlib 669 // Uncompress gzipped data with zlib
647 -+ (NSData *)uncompressZippedData:(NSData*)compressedData; 670 ++ (NSData *)uncompressZippedData:(NSData*)compressedData error:(NSError **)err;
648 671
649 // Uncompress gzipped data from a file into another file, used when downloading to a file 672 // Uncompress gzipped data from a file into another file, used when downloading to a file
650 -+ (int)uncompressZippedDataFromFile:(NSString *)sourcePath toFile:(NSString *)destinationPath; 673 ++ (BOOL)uncompressZippedDataFromFile:(NSString *)sourcePath toFile:(NSString *)destinationPath error:(NSError **)err;
651 + (int)uncompressZippedDataFromSource:(FILE *)source toDestination:(FILE *)dest; 674 + (int)uncompressZippedDataFromSource:(FILE *)source toDestination:(FILE *)dest;
652 675
653 #pragma mark gzip compression 676 #pragma mark gzip compression
654 677
655 // Compress data with gzip using zlib 678 // Compress data with gzip using zlib
656 -+ (NSData *)compressData:(NSData*)uncompressedData; 679 ++ (NSData *)compressData:(NSData*)uncompressedData error:(NSError **)err;
657 680
658 // gzip compress data from a file, saving to another file, used for uploading when shouldCompressRequestBody is true 681 // gzip compress data from a file, saving to another file, used for uploading when shouldCompressRequestBody is true
659 -+ (int)compressDataFromFile:(NSString *)sourcePath toFile:(NSString *)destinationPath; 682 ++ (BOOL)compressDataFromFile:(NSString *)sourcePath toFile:(NSString *)destinationPath error:(NSError **)err;
660 + (int)compressDataFromSource:(FILE *)source toDestination:(FILE *)dest; 683 + (int)compressDataFromSource:(FILE *)source toDestination:(FILE *)dest;
661 684
662 #pragma mark get user agent 685 #pragma mark get user agent
@@ -774,6 +797,7 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount; @@ -774,6 +797,7 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount;
774 @property (assign) BOOL useSessionPersistence; 797 @property (assign) BOOL useSessionPersistence;
775 @property (retain) NSString *downloadDestinationPath; 798 @property (retain) NSString *downloadDestinationPath;
776 @property (retain) NSString *temporaryFileDownloadPath; 799 @property (retain) NSString *temporaryFileDownloadPath;
  800 +@property (retain) NSString *temporaryUncompressedDataDownloadPath;
777 @property (assign) SEL didStartSelector; 801 @property (assign) SEL didStartSelector;
778 @property (assign) SEL didReceiveResponseHeadersSelector; 802 @property (assign) SEL didReceiveResponseHeadersSelector;
779 @property (assign) SEL didFinishSelector; 803 @property (assign) SEL didFinishSelector;
This diff is collapsed. Click to expand it.