urioutputstream package¶
This package allows to read files in a cross-platform way.
It has been tested on Android and Windows, but should also work on Linux and macOS.
It is used by UriFile.open()
when mode
is “wb” or “wt”
UriOutputStream class¶
- class tatogalib.uri_io.urioutputstream.UriOutputStream(uristring, mode, fnLog=None)¶
Creates a UriOutputStream which wraps a RawIOBase stream. This class supports the context manager protocol.
- Parameters:
uristring (str) – The URI-string of the stream
mode (str) – “wb” for overwriting, “ab” for appending
fnLog (callable) – The callable which is called from the log method It expects a string parameter
- close()¶
Flushes and closes the stream
- property closed¶
Checks if the stream is closed
- Returns:
True when closed, False otherwise
- flush()¶
Flushes the write buffer of stream if applicable
- isatty()¶
This method always returns False
- Returns:
False
- log(message)¶
Logs a message to the user code if fnLog was passed to the constructor
- Parameters:
message (str) – The message to be logged
- read(maxsize=-1)¶
This method will raise an OS error when it is called
- readable()¶
This method always returns False
- Returns:
False
- readall()¶
This method will raise an OS error when it is called
- readinto(bytesobj)¶
This method will raise an OS error when it is called
- seekable()¶
Checks if the stream is seekable
- Returns:
True when seekable, False otherwise
- truncate(size=None)¶
Resizes the stream to the given size. This is currently unimplemented on Android
- Parameters:
size (int) – The new size in bytes
- Returns:
The new size in bytes
- Return type:
int
- writable()¶
Checks if the stream is writable
- Returns:
True when writable, False otherwise
- write(bytesobj)¶
Writes bytes to the stream
- Parameters:
bytesobj (bytes) – The bytes to be written
- Returns:
The amount of bytes written
- Return type:
int
UriTextOutputStream class¶
- class tatogalib.uri_io.urioutputstream.UriTextOutputStream(uristring, mode, encoding, newline=None, fnLog=None)¶
Creates a UriTextOutputStream which wraps a UriOutputStream. This class supports the context manager protocol.
- Parameters:
uristring (str) – The URI-string of the stream
mode (str) – “wt” for overwriting, “at” for appending
encoding (str) – The encoding of the text, e.g. “utf-8”. Do not use “utf-8-sig” when you intend to
write
several times to the stream or you will have the BOM marker not only at the beginning, but also within the file.newline (str) – The characters to mark the end-of-line. It can be
\n
,\r
,\r\n
or None. When None, the system default value for the platform is used.fnLog (callable) – The callable which is called from the log method It expects a string parameter
- close()¶
Flushes and closes the stream
- property closed¶
Checks if the stream is closed
- Returns:
True when closed, False otherwise
- flush()¶
Flushes the write buffer of stream if applicable
- isatty()¶
This method always returns False
- Returns:
False
- log(message)¶
Logs a message to the user code if fnLog was passed to the constructor
- Parameters:
message (str) – The message to be logged
- read(maxsize=-1)¶
This method will raise an OS error when it is called
- readable()¶
This method always returns False
- Returns:
False
- readall()¶
This method will raise an OS error when it is called
- readinto(bytesobj)¶
This method will raise an OS error when it is called
- seekable()¶
Checks if the stream is seekable
- Returns:
True when seekable, False otherwise
- truncate(size=None)¶
Resizes the stream to the given size. This is currently unimplemented on Android
- Parameters:
size (int) – The new size in bytes
- Returns:
The new size in bytes
- Return type:
int
- writable()¶
Checks if the stream is writable
- Returns:
True when writable, False otherwise
- write(string)¶
Writes a string to the stream
- Parameters:
string (str) – The string to be written
- Returns:
The amount of characters written
- Return type:
int