-
Notifications
You must be signed in to change notification settings - Fork 12
/
pymjpeg.py
31 lines (27 loc) · 929 Bytes
/
pymjpeg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import os, time
boundary = '--boundarydonotcross'
def request_headers():
return {
'Cache-Control': 'no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0',
'Connection': 'close',
'Content-Type': 'multipart/x-mixed-replace;boundary=%s' % boundary,
'Expires': 'Mon, 1 Jan 2030 00:00:00 GMT',
'Pragma': 'no-cache',
'Access-Control-Allow-Origin': '*' # CORS
}
def image_headers(filename):
return {
'X-Timestamp': time.time(),
'Content-Length': os.path.getsize(filename),
#FIXME: mime-type must be set according file content
'Content-Type': 'image/jpeg',
}
# FIXME: should take a binary stream
def image(filename):
with open(filename, "rb") as f:
# for byte in f.read(1) while/if byte ?
byte = f.read(1)
while byte:
yield byte
# Next byte
byte = f.read(1)