response.py 486 B

12345678910111213141516171819202122
  1. # -*- coding: utf-8 -*-
  2. class FileResponse:
  3. """read a file piece by piece.
  4. Default chunk size 0x4000 bytes"""
  5. def __init__(self,
  6. file_location = '/',
  7. chunksize = int(0x4000)):
  8. self.file_location = file_location
  9. self.chunksize = chunksize
  10. def __iter__(self):
  11. with open(self.file_location, 'rb') as entry:
  12. for chunk in iter(lambda: entry.read(self.chunksize), b''):
  13. yield chunk