Skip to content

Limit the number of bytes that can be read from an object. Makes your code more secure.

License

Notifications You must be signed in to change notification settings

tebeka/limit_reader

Repository files navigation

LimitReader - Wrap readers with a limit

A port of Go's io.LimitReader to Python.

Examples

HTTP Requests

>>> from urllib.request import urlopen
>>> from limit_reader import LimitReader
>>> with urlopen('https://httpbin.org/bytes/1000') as resp:
...     rdr = LimitReader(resp, 353)
...     print(rdr.status)  # proxies method
...     data = rdr.read()
... 
200
>>> print(len(data))
353

Files

>>> with open('README.md') as fp:
...     rdr = LimitReader(fp, 17)
...     print(rdr.name)  # proxied attribute
...     data = rdr.read()
... 
README.md
>>> print(len(data))
17

About

Limit the number of bytes that can be read from an object. Makes your code more secure.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages