def get(self, ext): cube = get_cube() data, hdr = get_data(cube, ext.upper(), header=True) results = {'stream': cube, 'header': hdr.tostring(), 'data': data} return Response(orjson.dumps(results, option=orjson.OPT_SERIALIZE_NUMPY), mimetype='application/json')
async def fits_ext(ext: str): cube = get_cube() data, hdr = get_data(cube, ext.upper(), header=True) results = {'stream': cube, 'header': hdr.tostring(), 'data': data} # this is temporary until fastapi.responses.ORJSONResponse can accept options #return ORJSONResponseCustom(results, option=orjson.OPT_SERIALIZE_NUMPY) return Response(orjson.dumps(results, option=orjson.OPT_SERIALIZE_NUMPY), media_type='application/json')
def streaming_response(): ''' stream a file-like object as a response ''' cube = get_cube() file_like = open(cube, mode="rb") return StreamingResponse(file_like, media_type='application/octet-stream')
async def file_response(): ''' async streams a file as a response ''' cube = get_cube() name = get_path('mangacube', full=cube, ptype='name') # fileresponse is used for streaming downloads return FileResponse(cube, filename=name, media_type='application/gzip')
async def async_header(): cube = get_cube() hdr = get_header(cube) results = {'stream': cube, 'header': hdr.tostring()} return results
async def download_file(): cube = get_cube() return await send_file(cube, as_attachment=True)
async def json(ext): cube = get_cube() data, hdr = get_data(cube, ext=ext.upper(), header=True) results = {'stream': cube, 'header': hdr.tostring(), 'data': data} compressed = await compdata(results) return Response(compressed, mimetype='application/json')
def get(self): cube = get_cube() return send_file(cube, as_attachment=True)
def get(self): cube = get_cube() hdr = get_header(cube) results = {'stream': cube, 'header': hdr.tostring()} return results