wx.InputStream¶
wx.InputStream is an abstract base class which may not be used directly.
It is the base class of all streams which provide a Read
function, i.e. which can be used to read data from a source (e.g. a file, a socket, etc).
If you want to create your own input stream, you’ll need to derive from this class and implement the protected OnSysRead
function only.
Class Hierarchy¶
Known Subclasses¶
FFileInputStream , FileInputStream , FilterInputStream , MemoryInputStream , SocketInputStream , StringInputStream
Methods Summary¶
Creates a dummy input stream. |
|
Returns |
|
Returns |
|
Returns the first character in the input queue and removes it, blocking until it appears if necessary. |
|
Returns the last number of bytes read. |
|
Returns the first character in the input queue without removing it. |
|
Reads the specified amount of bytes and stores the data in buffer. |
|
Reads exactly the specified number of bytes into the buffer. |
|
Changes the stream current position. |
|
Returns the current stream position or |
|
This function is only useful in read mode. |
|
Properties Summary¶
See |
Class API¶
- class wx.InputStream(StreamBase)¶
Possible constructors:
InputStream() -> None
InputStream is an abstract base class which may not be used directly.
Methods¶
- __init__(self)¶
Creates a dummy input stream.
- Return type:
None
- CanRead(self)¶
Returns
True
if some data is available in the stream right now, so that callingRead
wouldn’t block.- Return type:
bool
- Eof(self)¶
Returns
True
after an attempt has been made to read past the end of the stream.- Return type:
bool
- GetC(self)¶
Returns the first character in the input queue and removes it, blocking until it appears if necessary.
On success returns a value between 0 - 255; on end of file returns
EOF
.- Return type:
int
- LastRead(self)¶
Returns the last number of bytes read.
- Return type:
int
- Peek(self)¶
Returns the first character in the input queue without removing it.
- Return type:
str
- Read(self, *args, **kw)¶
-
Read (self, buffer, size)
Reads the specified amount of bytes and stores the data in buffer.
To check if the call was successful you must use
LastRead
to check if this call did actually read size bytes (if it didn’t,GetLastError
should return a meaningful value).- Parameters:
buffer
size (int)
- Return type:
- Returns:
This function returns a reference on the current object, so the user can test any states of the stream right away.
Warning
The buffer absolutely needs to have at least the specified size.
Read (self, stream_out)
Reads data from the input queue and stores it in the specified output stream.
The data is read until an error is raised by one of the two streams.
- Parameters:
stream_out (wx.OutputStream)
- Return type:
- Returns:
This function returns a reference on the current object, so the user can test any states of the stream right away.
- ReadAll(self, buffer, size)¶
Reads exactly the specified number of bytes into the buffer.
Returns
True
only if the entire amount of data was read, otherwiseFalse
is returned and the number of bytes really read can be retrieved usingLastRead
, as withRead
.This method uses repeated calls to
Read
(which may return after reading less than the requested number of bytes) if necessary.- Parameters:
buffer
size (int)
- Return type:
bool
Added in version 2.9.5.
Warning
The buffer absolutely needs to have at least the specified size.
- SeekI(self, pos, mode=FromStart)¶
Changes the stream current position.
This operation in general is possible only for seekable streams (see
wx.StreamBase.IsSeekable
); non-seekable streams support only seeking positive amounts in modeFromCurrent
(this is implemented by reading data and simply discarding it).- Parameters:
pos (wx.FileOffset) – Offset to seek to.
mode (SeekMode) – One of FromStart, FromEnd, FromCurrent.
- Return type:
wx.FileOffset
- Returns:
The new stream position or
InvalidOffset
on error.
- TellI(self)¶
Returns the current stream position or
InvalidOffset
if it’s not available (e.g.socket streams do not have a size nor a current stream position).
- Return type:
wx.FileOffset
- Ungetch(self, *args, **kw)¶
-
Ungetch (self, buffer, size)
This function is only useful in read mode.
It is the manager of the “Write-Back” buffer. This buffer acts like a temporary buffer where data which has to be read during the next read
IO
call are put. This is useful when you get a big block of data which you didn’t want to read: you can replace them at the top of the input queue by this way.Be very careful about this call in connection with calling
SeekI
on the same stream. Any call toSeekI
will invalidate any previous call to this method (otherwise you couldSeekI
to one position, “unread” a few bytes there,SeekI
to another position and data would be either lost or corrupted).- Parameters:
buffer
size (int)
- Return type:
int
- Returns:
Returns the amount of bytes saved in the Write-Back buffer.
Ungetch (self, c)
This function acts like the previous one except that it takes only one character: it is sometimes shorter to use than the generic function.
- Parameters:
c (int)
- Return type:
bool
- close(self)¶
- Return type:
None
- eof(self)¶
- Return type:
bool
- flush(self)¶
- Return type:
None
- read(self, *args, **kw)¶
-
read (self)
- Return type:
Any
read (self, size)
- Return type:
Any
- readline(self, *args, **kw)¶
-
readline (self)
- Return type:
Any
readline (self, size)
- Return type:
Any
- readlines(self, *args, **kw)¶
-
readlines (self)
- Return type:
Any
readlines (self, sizehint)
- Return type:
Any
- seek(self, offset, whence=0)¶
- Return type:
None
- tell(self)¶
- Return type:
wx.FileOffset
Properties¶