-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add class FileResponse; universal response for a single file
- Loading branch information
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |