Skip to content

Commit

Permalink
2.5.3 - Add a BytesFifo class
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaughn Kottler authored and vkottler committed Aug 17, 2023
1 parent 57dd93d commit 55ed76b
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
- run: |
mk python-release owner=vkottler \
repo=vcorelib version=2.5.2
repo=vcorelib version=2.5.3
if: |
matrix.python-version == '3.11'
&& matrix.system == 'ubuntu-latest'
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<!--
=====================================
generator=datazen
version=3.1.2
hash=196da1477faa3b759390faa10cbe5229
version=3.1.3
hash=cd64e550ea85beda2288925dfaffc912
=====================================
-->

# vcorelib ([2.5.2](https://pypi.org/project/vcorelib/))
# vcorelib ([2.5.3](https://pypi.org/project/vcorelib/))

[![python](https://img.shields.io/pypi/pyversions/vcorelib.svg)](https://pypi.org/project/vcorelib/)
![Build Status](https://github.com/vkottler/vcorelib/workflows/Python%20Package/badge.svg)
Expand Down
2 changes: 1 addition & 1 deletion local/variables/package.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
major: 2
minor: 5
patch: 2
patch: 3
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta:__legacy__"

[project]
name = "vcorelib"
version = "2.5.2"
version = "2.5.3"
description = "A collection of core Python utilities."
readme = "README.md"
requires-python = ">=3.8"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# =====================================
# generator=datazen
# version=3.1.2
# version=3.1.3
# hash=aa3f8de4be97b3a228df7e69c5398da6
# =====================================

Expand Down
2 changes: 1 addition & 1 deletion tasks/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# =====================================
# generator=datazen
# version=3.1.2
# version=3.1.3
# hash=9f62028523c3b5a953733ca89dcc3018
# =====================================
"""
Expand Down
20 changes: 20 additions & 0 deletions tests/io/test_fifo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
Test the 'io.fifo' module.
"""

# module under test
from vcorelib.io import ByteFifo


def test_bytes_fifo_basic():
"""Test basic interaction with a bytes FIFO."""

fifo = ByteFifo()

assert fifo.pop(1) is None

fifo.ingest(bytes(range(10)))

assert fifo.pop(5) == bytes(range(5))

assert fifo.pop(5)
6 changes: 3 additions & 3 deletions vcorelib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# =====================================
# generator=datazen
# version=3.1.2
# hash=ed9fa6e1144db755bd0f92b37c25dd66
# version=3.1.3
# hash=8c9bafd1832bb17ea81364ecfb8a9dc4
# =====================================

"""
Expand All @@ -10,7 +10,7 @@

DESCRIPTION = "A collection of core Python utilities."
PKG_NAME = "vcorelib"
VERSION = "2.5.2"
VERSION = "2.5.3"

# vcorelib-specific content.
DEFAULT_INDENT = 2
Expand Down
2 changes: 2 additions & 0 deletions vcorelib/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# internal
from vcorelib.io.abc import FileEntity, Serializable
from vcorelib.io.arbiter import ARBITER, DataArbiter
from vcorelib.io.fifo import ByteFifo
from vcorelib.io.file_writer import IndentedFileWriter
from vcorelib.io.types import (
DataDecoder,
Expand Down Expand Up @@ -40,4 +41,5 @@
"FileEntity",
"DEFAULT_INCLUDES_KEY",
"IndentedFileWriter",
"ByteFifo",
]
35 changes: 35 additions & 0 deletions vcorelib/io/fifo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
A module implementing a simple bytes FIFO interface.
"""

# built-in
from typing import Optional as _Optional


class ByteFifo:
"""A simple fifo for bytes."""

def __init__(self) -> None:
"""Initialize this instance."""

self.data = bytes()
self.size = 0

def ingest(self, data: bytes) -> None:
"""Append new data to the end."""

self.data += data
self.size = len(self.data)

def pop(self, size: int) -> _Optional[bytes]:
"""Attempt to read some number of bytes from the front."""

result = None

if self.size >= size:
result = self.data[:size]

self.data = self.data[size:]
self.size -= size

return result

0 comments on commit 55ed76b

Please sign in to comment.