moat-lib-ring
% start synopsis % start main
A simple opinionated character-based ring buffer.
This buffer, well, buffers. It's async compatible and can handle writes overruns either by delaying the writer or by only keeping the newest data.
% end synopsis
Async operation
moat.lib.ring.aio provides an async version.
Async writes always wait until all bytes have been delivered to the buffer.
% end main
Usage
Usage is very simple:
from moat.lib.ring import RingBuffer
# Create buffer
ring = RingBuffer(200)
# write to it
nbytes = ring.write(b'Hello', drop=True)
assert nbytes == 5
# read from it
buf = bytearray(2)
assert ring.readinto(buf) == 2
assert buf == 'He'
Overflow handling
If you write with drop=True, which is the default, writing to the buffer
will always succeed and return the length of the bytestring. On overflow,
the last bufsize-1 bytes will be preserved. The first byte you read will be
a null byte, to signal that data was lost.
drop=False means that writing will stall instead of destroying data: write
will return a smaller length than requested. The caller is responsible for
waiting until there is free space.
Locking
This code doesn't know if it's called from a thread or not. If required, please add your own.
Threaded operation
TODO. Requires a lock and thread-based events (or conditions).
Metadata
Release files for moat-lib-ring 0.2.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| moat_lib_ring-0.2.5.tar.gz | 6.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| moat_lib_ring-0.2.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.4 kB
Release files / moat_lib_ring-0.2.5.tar.gz
| Download URL | moat_lib_ring-0.2.5.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b64aff29ab71be62eccc7aa295daa98a7c564a37c6796af0a9fc2967a0b06d59
|
|
BLAKE2b-256 checksum How to use checksums |
6e6ad49ba32d56d512fdd7e8bc6c4b1c434dad41d9aabe2ff0dd3c5fc96e67d9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / moat_lib_ring-0.2.5-py3-none-any.whl
| Download URL | moat_lib_ring-0.2.5-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cc05ed58565c5998ff9e0f91b906a9749c6dd3de9cba54d609063a5080160b64
|
|
BLAKE2b-256 checksum How to use checksums |
c647e11d421f5a5bb172bc1ebe0a28535b96d9c293a6a9f7223334cb8c12ab24
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|