Skip to content

Commit

Permalink
Merge pull request #945 from IGS/hotfix-942
Browse files Browse the repository at this point in the history
Hotfix 942
  • Loading branch information
adkinsrs authored Nov 11, 2024
2 parents b2689be + 83ad322 commit 3ea3343
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions www/cgi/download_source_file.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,29 @@ or H5AD file.
'''

from shutil import copyfileobj
import sys
import cgi, html, json
import os
import sys
import cgi, html

lib_path = os.path.abspath(os.path.join('..', '..', 'lib'))
sys.path.append(lib_path)
import geardb


def download_file(file_path, file_name):
print("Content-type: application/octet-stream")
print(f"Content-Disposition: attachment; filename={file_name}")
print()
sys.stdout.flush()

with open(file_path, 'rb') as binfile:
while True:
chunk = binfile.read(8192) # Read in 8KB chunks
if not chunk:
break
sys.stdout.buffer.write(chunk)
sys.stdout.buffer.flush()

def main():
form = cgi.FieldStorage()
dataset_id = html.escape(form.getvalue('dataset_id'))
Expand All @@ -40,23 +54,9 @@ def main():
h5ad_path = ""

if dtype == 'tarball' and os.path.isfile(tarball_path):
print("Content-type: application/octet-stream")
print("Content-Disposition: attachment; filename={0}.tar.gz".format(dataset_id))
print()
sys.stdout.flush()

with open(tarball_path, 'rb') as binfile:
copyfileobj(binfile, sys.stdout.buffer)

download_file(tarball_path, f"{dataset_id}.tar.gz")
elif dtype == 'h5ad' and os.path.isfile(h5ad_path):
print("Content-type: application/octet-stream")
print("Content-Disposition: attachment; filename={0}.h5ad".format(dataset_id))
print()
sys.stdout.flush()

with open(h5ad_path, 'rb') as binfile:
copyfileobj(binfile, sys.stdout.buffer)

download_file(h5ad_path, f"{dataset_id}.h5ad")
else:
raise FileNotFoundError("File not found")

Expand Down

0 comments on commit 3ea3343

Please sign in to comment.