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).
Release files for moat-lib-ring 0.2.4
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.4.tar.gz | 6.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| moat_lib_ring-0.2.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.3 kB
Release files / moat_lib_ring-0.2.4.tar.gz
| Download URL | moat_lib_ring-0.2.4.tar.gz |
|---|---|
| Size | 6.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3d5b688f8d2ad839ebe392b4e01fdb4b92b2ea69f4a51af35fa467fbd58ef118
|
|
BLAKE2b-256 checksum How to use checksums |
ffec2e3fff4fdedc761bdc0cc761a2a4a79dd33cb4976cd545d25fd309f9eb08
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Release files / moat_lib_ring-0.2.4-py3-none-any.whl
| Download URL | moat_lib_ring-0.2.4-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d90cfb27a7434a4d9dfcc6eef71f9a48d4201cd580901f9c57a8be72c6d74b8c
|
|
BLAKE2b-256 checksum How to use checksums |
4e691c8d009fa848245d372729236d7fc2e81e49208ad2ea8b39bfbb594f964c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|