Skip to content

Commit 2004a83

Browse files
author
Benjamin Moody
committed
wfdb.io.download: add _get_url function.
This function provides a simple wrapper for requests.get, handling the common case of reading the entire contents of a binary file and raising an exception if the file doesn't exist. This function is a temporary shim to assist in porting the wfdb.io.download functions to using wfdb.io._url.
1 parent 93d7753 commit 2004a83

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

wfdb/io/download.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,29 @@ def set_db_index_url(db_index_url=PN_INDEX_URL):
4949
config.db_index_url = db_index_url
5050

5151

52+
def _get_url(url):
53+
"""
54+
Retrieve an entire remote file as bytes.
55+
56+
Parameters
57+
----------
58+
url : str
59+
URL of the remote file.
60+
61+
Returns
62+
-------
63+
content : bytes
64+
Content of the remote file.
65+
66+
"""
67+
response = requests.get(url)
68+
if response.status_code == 404:
69+
raise FileNotFoundError
70+
else:
71+
response.raise_for_status()
72+
return response.content
73+
74+
5275
def _remote_file_size(url=None, file_name=None, pn_dir=None):
5376
"""
5477
Get the remote file size in bytes.

0 commit comments

Comments
 (0)