This commit is contained in:
yumoqing 2025-09-14 20:33:12 +08:00
parent acc2474479
commit 3548f8303e

View File

@ -119,6 +119,28 @@ class FileStorage:
except Exception as e:
exception(f'{path=}, {p=} remove error')
async def streaming_read(request, webpath, buf_size=8096):
fp = self.realPath(webpath)
stats = os.stat(fp)
startpos = 0
endpos = stats.st_size
range = request.headers.get('Range')
if range:
s,e = range.split('-')
if s:
startpos = int(s)
if e:
endpos = int(e)
debug(f'filesize={stats.st_size}, {startpos=}, {endpos=}')
async with aiofiles.open(fp, 'rb') as f:
if startpos > 0:
await f.seek(startpos)
pos = startpos
while pos < endpos:
b = f.read(buf_size)
yield b
pos += len(b)
async def save(self,name,read_data, userid=None):
p = self._name2path(name, userid=userid)
fpath = p[len(self.root):]