Skip to content

Instantly share code, notes, and snippets.

@ricardocuellar
Created October 9, 2025 04:57
Show Gist options
  • Select an option

  • Save ricardocuellar/76e78ab1514bbca6e7451b3ed84b510f to your computer and use it in GitHub Desktop.

Select an option

Save ricardocuellar/76e78ab1514bbca6e7451b3ed84b510f to your computer and use it in GitHub Desktop.
Chunk Reader
class _ChunkCounter:
def __init__(self, f):
self._f = f
self.calls = 0
self.sizes = []
def read(self, n=-1):
data = self._f.read(n)
if data:
self.calls += 1
self.sizes.append(len(data))
return data
def __getattr__(self, name): # delega cualquier otro atributo
return getattr(self._f, name)
reader = _ChunkCounter(file.file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment