-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMDBufferedInputStream.h
More file actions
74 lines (60 loc) · 2.5 KB
/
MDBufferedInputStream.h
File metadata and controls
74 lines (60 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
// MDBufferedInputStream.h
// A NSInputStream decorator that adds buffering and text parsing functionality
// Text is returned line by line through the readLine method
//
// Created by Federico Mestrone on 07/04/2010.
// Copyright 2010 Moodsdesign Ltd. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface MDBufferedInputStream : NSInputStream {
// The decorated stream
NSInputStream *stream;
// The size of each chunk read from the stream into memory
NSUInteger bufSize;
// The encoding of the text represented by the underlying stream
NSStringEncoding encoding;
// Buffer containing the bytes of the current chunk read from the stream
uint8_t *dataBuffer;
// Temporary buffer of the bytes of the current line till a line termination marker is reached
// Only when a line ending is reached can the bytes safely be decoded into a string
NSMutableData *lineBuffer;
// The position being read from the current chunk
NSInteger pos;
// The number of bytes read from the stream into the chunk
NSInteger read;
// The number of bytes actually processed so far
NSUInteger bytesProcessed;
// Whether the stream was opened by this decorator and should therefore be closed with it
BOOL shouldCloseStream;
// Whether the object should return empty lines or not
BOOL wantsEmptyLines;
// Whether the object should trim lines before returning them
BOOL trimLines;
/**********************************
CSV Files
**********************************/
NSArray *csvTitles;
unichar quote;
unichar separator;
}
// Returns the number of bytes that have currently been processed by the decorator
@property (readonly) NSUInteger bytesProcessed;
// Returns or sets whether the object returns empty lines or not
@property BOOL wantsEmptyLines;
// Returns or sets whether the object should trim lines before returning them
@property BOOL trimLines;
// Creates a new decorator with the given stream, chunk size, and encoding
- (id) initWithInputStream:(NSInputStream *)stream bufferSize:(NSUInteger)bufSize encoding:(NSStringEncoding)encoding;
// Read a new line of text from the underlying stream
- (NSString *) readLine;
/**********************************
CSV Files
**********************************/
// Returns or sets the titles for each field of a CSV file
@property (retain) NSArray *csvTitles;
// Read the line of CSV header titles from the underlying stream
- (NSArray *) csvReadHeader;
// Read a new line of CSV text data from the underlying stream
- (NSDictionary *) csvReadData;
@end