#include <evo/impl/sysio.h>
Buffered reader for IoDevice (used internally).
- This is an internal low-level interface, see: File, Pipe, Console, Socket
- Filtering is enabled by setting 'filters' – note that the pointer should be owned (freed) by the IoDevice
- Use readbuf.resize() to resize or disable buffer – note that filters require buffering
- Members are public for quick access and simple low-level interface
|
| IoReader (ulong newsize=0, Newline nl=NL_SYS) |
| Constructor to set new buffer size. More...
|
|
void | close () |
| Close input. More...
|
|
template<class T > |
Error | fill (T &in, ulong minsize=0) |
| Reset and fill buffer by reading from file. More...
|
|
void | open () |
| Initialize and open for input (reading). More...
|
|
template<class T > |
ulong | readbin (Error &err, T &in, void *buf, ulong bufsize) |
| Read from file using buffer. More...
|
|
template<class T > |
Error | readline (String &str, T &in, ulong maxlen=0) |
| Read a line from file using buffer. More...
|
|
template<class T > |
ulong | readtext (Error &err, T &in, char *buf, ulong bufsize) |
| Read from file using buffer. More...
|
|
|
static const ulong | DEFSIZE = 8192 |
| Default buffer size (8KB, power of 2 and multiple of common filesystem block size 4KB) More...
|
|
◆ IoReader()
Constructor to set new buffer size.
- Parameters
-
newsize | New buffer size, 0 for default |
nl | Newline value for text reading to convert newlines to (defaults to NL_SYS), doesn't affect reading by line |
◆ close()
◆ fill()
Error fill |
( |
T & |
in, |
|
|
ulong |
minsize = 0 |
|
) |
| |
|
inline |
Reset and fill buffer by reading from file.
- This will first reset buffer moving data at pos to beginning (and set pos to 0), data before pos is lost
- Next this will read from file and fill buffer until full, minsize reached, end-of-file is reached, or an error occurs
- Data may still be in buffer after end-of-file is reached
- The minsize parameter is useful when input is trickling in (slow network or user typing)
- Template Parameters
-
- Parameters
-
in | File to read from |
minsize | Minimum size to fill (capped to buffer size if greater), 0 for whole buffer |
- Returns
- ENone on success, EEnd if end-of-file reached, error code on other error
◆ open()
Initialize and open for input (reading).
- This creates the read buffer, if needed
◆ readbin()
ulong readbin |
( |
Error & |
err, |
|
|
T & |
in, |
|
|
void * |
buf, |
|
|
ulong |
bufsize |
|
) |
| |
|
inline |
Read from file using buffer.
- May return less than requested
- This does a binary read – no conversion on newlines
- Template Parameters
-
- Parameters
-
err | Stores ENone on success, error code on error [out] |
in | File to read from |
buf | Buffer to store data read |
bufsize | Size in bytes to read from file (must be positive) |
- Returns
- Bytes read, 0 if end-of-file or error (check err)
◆ readline()
Error readline |
( |
String & |
str, |
|
|
T & |
in, |
|
|
ulong |
maxlen = 0 |
|
) |
| |
|
inline |
Read a line from file using buffer.
- This will read and return the next line from file as a string, not including the newline
- This recognizes '\n', '\r', or either combination of the two as a newline
- Template Parameters
-
- Parameters
-
str | String to store line (cleared first) [out] |
in | File to read from |
maxlen | Maximum line length, 0 for no limit |
- Returns
- ENone on success, EEnd if no more lines (end-of-file), EOutOfBounds if line exceeds maxlen, or error code on error
◆ readtext()
ulong readtext |
( |
Error & |
err, |
|
|
T & |
in, |
|
|
char * |
buf, |
|
|
ulong |
bufsize |
|
) |
| |
|
inline |
Read from file using buffer.
- May return less than requested
- This does a text read, converting newlines per newline member
- This recognizes '\n', '\r', or either combination of the two as a newline
- Note: This will try to avoid stopping in the middle of a newline pair by reading 1 less byte, if possible
- If forced to break up a newline pair due to bufsize=1 (not recommended), the remaining newline byte is saved until the next call to readtext()
- However, calling readline() after readtext() in this special case will cause readline() to return an ELoss error
- If this happens the solution is to read the remaining newline byte with bufsize=1, to detect this case:
- This is only a problem if you mix readtext() (with bufsize=1) and readline() calls under these conditions
- Template Parameters
-
- Parameters
-
err | Stores ENone on success, error code on error [out] |
in | File to read from |
buf | Buffer to store data read |
bufsize | Size in bytes to read from file (must be positive) |
- Returns
- Bytes read, 0 if end-of-file or error (check err)
◆ curbuf
Pointer to current buffer, either primary buffer or from last filter applied.
◆ curbuf_offset
Bytes read from curbuf, i.e. buffer start offset.
◆ DEFSIZE
const ulong DEFSIZE = 8192 |
|
static |
Default buffer size (8KB, power of 2 and multiple of common filesystem block size 4KB)
◆ newline
Newline string to convert to when reading text – do not modify.
◆ newlinesize
Size of newlines string to use, i.e. strlen(newline) – do not modify.
◆ rd_partnl
Used by readtext() in special case, holds end of converted newline that didn't fit in buf or 0.
◆ readbuf
Primary read buffer – filtering may involve additional buffers.
◆ rl_partnl
Used by readline() on partial newlines, holds next expected char for newline pair or 0.
◆ timeout_ms
Read timeout in milliseconds, 0 for none (don't timeout)
The documentation for this struct was generated from the following file: