diff options
-rw-r--r-- | MLKStream.h | 2 | ||||
-rw-r--r-- | MLKStream.m | 25 |
2 files changed, 26 insertions, 1 deletions
diff --git a/MLKStream.h b/MLKStream.h index cc67400..733b5ee 100644 --- a/MLKStream.h +++ b/MLKStream.h @@ -28,6 +28,8 @@ NSOutputStream *_output; NSStringEncoding _encoding; BOOL _charCached; + BOOL _closeInputWhenDone; + BOOL _closeOutputWhenDone; unichar _cachedChar; } diff --git a/MLKStream.m b/MLKStream.m index d77ff9c..f1c2b32 100644 --- a/MLKStream.m +++ b/MLKStream.m @@ -57,6 +57,8 @@ _encoding = encoding; _cachedChar = 0; _charCached = NO; + _closeInputWhenDone = NO; + _closeOutputWhenDone = NO; return self; } @@ -75,6 +77,12 @@ return ch; } + if ([_input streamStatus] == NSStreamStatusNotOpen) + { + _closeInputWhenDone = YES; + [_input open]; + } + buffer = NULL; for (i = 0;; i++) { @@ -85,7 +93,7 @@ buffer = realloc (buffer, i+1); bytes_read = [_input read:(buffer+i) maxLength:1]; - NSLog (@"%d bytes read", bytes_read); + //NSLog (@"%d bytes read", bytes_read); if (bytes_read < 1) { @@ -149,4 +157,19 @@ return eofp; } + +-(void) dealloc +{ + if (_closeInputWhenDone) + { + [_input close]; + } + RELEASE (_input); + if (_closeOutputWhenDone) + { + [_output close]; + } + RELEASE (_output); + [super dealloc]; +} @end |