io-wrapper

Installation
SKILL.md

When to use

To wrap a file-like object and count reads/writes.

Rules

  • Store the wrapped object as self._wrapped
  • Implement read(size=-1) by delegating to self._wrapped.read(size)
  • Increment counters by the length of the RETURNED bytes, NOT the requested size
  • For write: increment nwrites by the RETURN VALUE, or by len(data) if the wrapped write returns None
  • Expose read_bytes/nreads and write_bytes/nwrites as properties or attributes
  • enter returns self; exit calls self._wrapped.exit (or close()) and forwards the exception info
  • ALWAYS implement close() as a plain method for non-context-manager use
  • NEVER count requested bytes — only count what was actually returned/written

Edge cases

Thread safety: if the test uses threads, wrap counter updates in a threading.Lock.

Installs
2
Repository
knoopx/pi
GitHub Stars
59
First Seen
May 24, 2026
io-wrapper — knoopx/pi