Skip to content

Commit

Permalink
add class FileResponse; universal response for a single file
Browse files Browse the repository at this point in the history
  • Loading branch information
sandes committed May 21, 2020
1 parent 97a3c79 commit 6928c49
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions zipfly/response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-

class FileResponse:

"""read a file piece by piece.
Default chunk size 0x4000 bytes"""

def __init__(self,
file_location = '/',
chunksize = int(0x4000)):

self.file_location = file_location
self.chunksize = chunksize


def __iter__(self):

with open(self.file_location, 'rb') as entry:

for chunk in iter(lambda: entry.read(self.chunksize), b''):

yield chunk

0 comments on commit 6928c49

Please sign in to comment.