Permalink
Browse files

Fix output stream status not updating

  • Loading branch information...
1 parent 4e15bde commit 2d77bca5efeecf02308de903404ec9423d2664bc @pixelglow committed Feb 2, 2013
Showing with 27 additions and 2 deletions.
  1. +1 −0 zipzap/ZZDeflateOutputStream.h
  2. +13 −0 zipzap/ZZDeflateOutputStream.m
  3. +3 −2 zipzap/ZZStoreOutputStream.h
  4. +10 −0 zipzap/ZZStoreOutputStream.m
@@ -19,6 +19,7 @@
- (id)initWithChannelOutput:(id<ZZChannelOutput>)channelOutput
compressionLevel:(NSUInteger)compressionLevel;
+- (NSStreamStatus)streamStatus;
- (NSError*)streamError;
- (void)open;
@@ -17,6 +17,7 @@ @implementation ZZDeflateOutputStream
{
id<ZZChannelOutput> _channelOutput;
NSUInteger _compressionLevel;
+ NSStreamStatus _status;
NSError* _error;
uint32_t _crc32;
z_stream _stream;
@@ -31,6 +32,7 @@ - (id)initWithChannelOutput:(id<ZZChannelOutput>)channelOutput compressionLevel:
_channelOutput = channelOutput;
_compressionLevel = compressionLevel;
+ _status = NSStreamStatusNotOpen;
_error = nil;
_crc32 = 0;
_stream.zalloc = Z_NULL;
@@ -52,6 +54,11 @@ - (uint32_t)uncompressedSize
return (uint32_t)_stream.total_in;
}
+- (NSStreamStatus)streamStatus
+{
+ return _status;
+}
+
- (NSError*)streamError
{
return _error;
@@ -65,6 +72,7 @@ - (void)open
-15,
8,
Z_DEFAULT_STRATEGY);
+ _status = NSStreamStatusOpen;
}
- (void)close
@@ -89,11 +97,15 @@ - (void)close
length:_flushLength - _stream.avail_out
freeWhenDone:NO]
error:&flushError])
+ {
+ _status = NSStreamStatusError;
_error = flushError;
+ }
}
}
deflateEnd(&_stream);
+ _status = NSStreamStatusClosed;
}
- (NSInteger)write:(const uint8_t*)buffer maxLength:(NSUInteger)length
@@ -118,6 +130,7 @@ - (NSInteger)write:(const uint8_t*)buffer maxLength:(NSUInteger)length
if (![_channelOutput writeData:outputBuffer
error:&writeError])
{
+ _status = NSStreamStatusError;
_error = writeError;
return -1;
}
@@ -17,11 +17,12 @@
- (id)initWithChannelOutput:(id<ZZChannelOutput>)channelOutput;
+- (NSStreamStatus)streamStatus;
+- (NSError*)streamError;
+
- (void)open;
- (void)close;
-- (NSError*)streamError;
-
- (NSInteger)write:(const uint8_t*)buffer maxLength:(NSUInteger)length;
- (BOOL)hasSpaceAvailable;
@@ -14,6 +14,7 @@
@implementation ZZStoreOutputStream
{
id<ZZChannelOutput> _channelOutput;
+ NSStreamStatus _status;
NSError* _error;
uint32_t _crc32;
uint32_t _size;
@@ -28,24 +29,32 @@ - (id)initWithChannelOutput:(id<ZZChannelOutput>)channelOutput
{
_channelOutput = channelOutput;
+ _status = NSStreamStatusNotOpen;
_error = nil;
_crc32 = 0;
_size = 0;
}
return self;
}
+- (NSStreamStatus)streamStatus
+{
+ return _status;
+}
+
- (NSError*)streamError
{
return _error;
}
- (void)open
{
+ _status = NSStreamStatusOpen;
}
- (void)close
{
+ _status = NSStreamStatusClosed;
}
- (NSInteger)write:(const uint8_t*)buffer maxLength:(NSUInteger)length
@@ -56,6 +65,7 @@ - (NSInteger)write:(const uint8_t*)buffer maxLength:(NSUInteger)length
freeWhenDone:NO]
error:&writeError])
{
+ _status = NSStreamStatusError;
_error = writeError;
return -1;
}

0 comments on commit 2d77bca

Please sign in to comment.