Skip to content

Commit

Permalink
Merge pull request #29 from jaydee3/master
Browse files Browse the repository at this point in the history
Added totalBytesRead Property
  • Loading branch information
davedelong committed Mar 6, 2013
2 parents b5b4c89 + b08ecfa commit 5fa02c6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions CHCSVParser.podspec
Expand Up @@ -4,7 +4,7 @@ Pod::Spec.new do |spec|
spec.homepage = 'https://github.com/davedelong/CHCSVParser'
spec.summary = 'A proper CSV parser for Objective-C.'
spec.license = 'MIT (LICENSE)'
spec.version = '2.0.3'
spec.source = { :git => 'https://github.com/davedelong/CHCSVParser', :tag => '2.0.3' }
spec.version = '2.0.4'
spec.source = { :git => 'https://github.com/davedelong/CHCSVParser', :tag => '2.0.4' }
spec.source_files = 'CHCSVParser/CHCSVParser.{h,m}'
end
2 changes: 2 additions & 0 deletions CHCSVParser/CHCSVParser.h
Expand Up @@ -57,6 +57,8 @@ typedef NSInteger CHCSVErrorCode;
@property (assign) BOOL sanitizesFields; // default is NO
@property (assign) BOOL recognizesComments; // default is NO

@property (readonly) NSUInteger totalBytesRead;

// designated initializer
- (id)initWithInputStream:(NSInputStream *)stream usedEncoding:(NSStringEncoding *)encoding delimiter:(unichar)delimiter;

Expand Down
6 changes: 6 additions & 0 deletions CHCSVParser/CHCSVParser.m
Expand Up @@ -49,6 +49,10 @@ of this software and associated documentation files (the "Software"), to deal

#endif

@interface CHCSVParser ()
@property (assign) NSUInteger totalBytesRead;
@end

@implementation CHCSVParser {
NSInputStream *_stream;
NSStringEncoding _streamEncoding;
Expand Down Expand Up @@ -142,6 +146,7 @@ - (void)_sniffEncoding {
uint8_t bytes[CHUNK_SIZE];
NSUInteger readLength = [_stream read:bytes maxLength:CHUNK_SIZE];
[_stringBuffer appendBytes:bytes length:readLength];
[self setTotalBytesRead:[self totalBytesRead] + readLength];

if (readLength > 0) {
NSStringEncoding encoding = NSUTF8StringEncoding;
Expand Down Expand Up @@ -195,6 +200,7 @@ - (void)_loadMoreIfNecessary {
if (readBytes > 0) {
// append it to the buffer
[_stringBuffer appendBytes:buffer length:readBytes];
[self setTotalBytesRead:[self totalBytesRead] + readBytes];
}
}

Expand Down

0 comments on commit 5fa02c6

Please sign in to comment.