.. wxPython Phoenix documentation
This file was generated by Phoenix's sphinx generator and associated
tools, do not edit by hand.
Copyright: (c) 2011-2020 by Total Control Software
License: wxWindows License
.. include:: headings.inc
.. _wx.InputStream:
==========================================================================================================================================
|phoenix_title| **wx.InputStream**
==========================================================================================================================================
:ref:`wx.InputStream` is an abstract base class which may not be used directly.
It is the base class of all streams which provide a :meth:`~wx.InputStream.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 :meth:`~wx.InputStream.OnSysRead` function only.
|
|class_hierarchy| Class Hierarchy
=================================
.. raw:: html

Inheritance diagram for class
InputStream:
|
|sub_classes| Known Subclasses
==============================
`FFileInputStream` , `FileInputStream` , `FilterInputStream` , `MemoryInputStream` , `SocketInputStream` , `StringInputStream`
|
|method_summary| Methods Summary
================================
================================================================================ ================================================================================
:meth:`~wx.InputStream.__init__` Creates a dummy input stream.
:meth:`~wx.InputStream.CanRead` Returns ``True`` if some data is available in the stream right now, so that calling :meth:`~InputStream.Read` wouldn't block.
:meth:`~wx.InputStream.Eof` Returns ``True`` after an attempt has been made to read past the end of the stream.
:meth:`~wx.InputStream.GetC` Returns the first character in the input queue and removes it, blocking until it appears if necessary.
:meth:`~wx.InputStream.LastRead` Returns the last number of bytes read.
:meth:`~wx.InputStream.Peek` Returns the first character in the input queue without removing it.
:meth:`~wx.InputStream.Read` Reads the specified amount of bytes and stores the data in buffer.
:meth:`~wx.InputStream.ReadAll` Reads exactly the specified number of bytes into the buffer.
:meth:`~wx.InputStream.SeekI` Changes the stream current position.
:meth:`~wx.InputStream.TellI` Returns the current stream position or :meth:`~InputStream.InvalidOffset` if it's not available (e.g.
:meth:`~wx.InputStream.Ungetch` This function is only useful in read mode.
:meth:`~wx.InputStream.close`
:meth:`~wx.InputStream.eof`
:meth:`~wx.InputStream.flush`
:meth:`~wx.InputStream.read`
:meth:`~wx.InputStream.readline`
:meth:`~wx.InputStream.readlines`
:meth:`~wx.InputStream.seek`
:meth:`~wx.InputStream.tell`
================================================================================ ================================================================================
|
|property_summary| Properties Summary
=====================================
================================================================================ ================================================================================
:attr:`~wx.InputStream.C` See :meth:`~wx.InputStream.GetC`
================================================================================ ================================================================================
|
|api| Class API
===============
.. class:: wx.InputStream(StreamBase)
**Possible constructors**::
InputStream() -> None
InputStream is an abstract base class which may not be used
directly.
.. method:: __init__(self)
Creates a dummy input stream.
:rtype: `None`
.. method:: CanRead(self)
Returns ``True`` if some data is available in the stream right now, so that calling :meth:`Read` wouldn't block.
:rtype: `bool`
.. method:: Eof(self)
Returns ``True`` after an attempt has been made to read past the end of the stream.
:rtype: `bool`
.. method:: 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`` .
:rtype: `int`
.. method:: LastRead(self)
Returns the last number of bytes read.
:rtype: `int`
.. method:: Peek(self)
Returns the first character in the input queue without removing it.
:rtype: `str`
.. method:: Read(self, *args, **kw)
|overload| **Overloaded Implementations:**
:html:`
`
**Read** `(self, buffer : Any, size : int)`
Reads the specified amount of bytes and stores the data in buffer.
To check if the call was successful you must use :meth:`LastRead` to check if this call did actually read `size` bytes (if it didn't, :meth:`~wx.StreamBase.GetLastError` should return a meaningful value).
:param `buffer`:
:param `size`:
:type `size`: int
:rtype: :ref:`wx.InputStream`
: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.
:html:`
`
**Read** `(self, stream_out : OutputStream)`
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.
:param `stream_out`:
:type `stream_out`: wx.OutputStream
:rtype: :ref:`wx.InputStream`
:returns:
This function returns a reference on the current object, so the user can test any states of the stream right away.
:html:`
`
.. method:: ReadAll(self, buffer : Any, size : int)
Reads exactly the specified number of bytes into the buffer.
Returns ``True`` only if the entire amount of data was read, otherwise ``False`` is returned and the number of bytes really read can be retrieved using :meth:`LastRead` , as with :meth:`Read` .
This method uses repeated calls to :meth:`Read` (which may return after reading less than the requested number of bytes) if necessary.
:param `buffer`:
:param `size`:
:type `size`: int
:rtype: `bool`
.. versionadded:: 2.9.5
.. warning:: The buffer absolutely needs to have at least the specified size.
.. method:: SeekI(self, pos : FileOffset, mode: SeekMode=FromStart)
Changes the stream current position.
This operation in general is possible only for seekable streams (see :meth:`wx.StreamBase.IsSeekable` ); non-seekable streams support only seeking positive amounts in mode ``FromCurrent`` (this is implemented by reading data and simply discarding it).
:param `pos`: Offset to seek to.
:type `pos`: wx.FileOffset
:param `mode`: One of FromStart, FromEnd, FromCurrent.
:type `mode`: wx.SeekMode
:rtype: `wx.FileOffset`
:returns:
The new stream position or :meth:`InvalidOffset` on error.
.. method:: TellI(self)
Returns the current stream position or :meth:`InvalidOffset` if it's not available (e.g.
socket streams do not have a size nor a current stream position).
:rtype: `wx.FileOffset`
.. method:: Ungetch(self, *args, **kw)
|overload| **Overloaded Implementations:**
:html:`
`
**Ungetch** `(self, buffer : Any, size : int)`
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 :meth:`SeekI` on the same stream. Any call to :meth:`SeekI` will invalidate any previous call to this method (otherwise you could :meth:`SeekI` to one position, "unread" a few bytes there, :meth:`SeekI` to another position and data would be either lost or corrupted).
:param `buffer`:
:param `size`:
:type `size`: int
:rtype: `int`
:returns:
Returns the amount of bytes saved in the Write-Back buffer.
:html:`
`
**Ungetch** `(self, c : str)`
This function acts like the previous one except that it takes only one character: it is sometimes shorter to use than the generic function.
:param `c`:
:type `c`: int
:rtype: `bool`
:html:`
`
.. method:: close(self)
:rtype: `None`
.. method:: eof(self)
:rtype: `bool`
.. method:: flush(self)
:rtype: `None`
.. method:: read(self, *args, **kw)
|overload| **Overloaded Implementations:**
:html:`
`
**read** `(self)`
:rtype: `Any`
:html:`
`
**read** `(self, size: int)`
:rtype: `Any`
:html:`
`
.. method:: readline(self, *args, **kw)
|overload| **Overloaded Implementations:**
:html:`
`
**readline** `(self)`
:rtype: `Any`
:html:`
`
**readline** `(self, size: int)`
:rtype: `Any`
:html:`
`
.. method:: readlines(self, *args, **kw)
|overload| **Overloaded Implementations:**
:html:`
`
**readlines** `(self)`
:rtype: `Any`
:html:`
`
**readlines** `(self, sizehint: int)`
:rtype: `Any`
:html:`
`
.. method:: seek(self, offset: FileOffset, whence: int=0)
:rtype: `None`
.. method:: tell(self)
:rtype: `wx.FileOffset`
.. attribute:: C
See :meth:`~wx.InputStream.GetC`