Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 43 lines (32 sloc) 1.836 kb
76d2a5b @mstroeck
mstroeck authored
1 //
2 // ASIDataCompressor.h
3 // Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest
4 //
5 // Created by Ben Copsey on 17/08/2010.
6 // Copyright 2010 All-Seeing Interactive. All rights reserved.
7 //
8
9 // This is a helper class used by ASIHTTPRequest to handle deflating (compressing) data in memory and on disk
10 // You may also find it helpful if you need to deflate data and files yourself - see the class methods below
11 // Most of the zlib stuff is based on the sample code by Mark Adler available at http://zlib.net
12
13 #import <Foundation/Foundation.h>
14 #import <zlib.h>
15
16 @interface ASIDataCompressor : NSObject {
17 BOOL streamReady;
18 z_stream zStream;
19 }
20
21 // Convenience constructor will call setupStream for you
22 + (id)compressor;
23
24 // Compress the passed chunk of data
25 // Passing YES for shouldFinish will finalize the deflated data - you must pass YES when you are on the last chunk of data
26 - (NSData *)compressBytes:(Bytef *)bytes length:(NSUInteger)length error:(NSError **)err shouldFinish:(BOOL)shouldFinish;
27
28 // Convenience method - pass it some data, and you'll get deflated data back
29 + (NSData *)compressData:(NSData*)uncompressedData error:(NSError **)err;
30
31 // Convenience method - pass it a file containing the data to compress in sourcePath, and it will write deflated data to destinationPath
32 + (BOOL)compressDataFromFile:(NSString *)sourcePath toFile:(NSString *)destinationPath error:(NSError **)err;
33
34 // Sets up zlib to handle the inflating. You only need to call this yourself if you aren't using the convenience constructor 'compressor'
35 - (NSError *)setupStream;
36
37 // Tells zlib to clean up. You need to call this if you need to cancel deflating part way through
38 // If deflating finishes or fails, this method will be called automatically
39 - (NSError *)closeStream;
40
41 @property (assign, readonly) BOOL streamReady;
42 @end
Something went wrong with that request. Please try again.