Skip to content

Commit ac3a0b5

Browse files
author
Benjamin Moody
committed
_stream_dat: use openurl in place of requests.get.
Note that this will correctly handle remote files that do not support random access.
1 parent 442383b commit ac3a0b5

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

wfdb/io/download.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,19 +184,13 @@ def _stream_dat(file_name, pn_dir, byte_count, start_byte, dtype):
184184
# Full url of dat file
185185
url = posixpath.join(config.db_index_url, pn_dir, file_name)
186186

187-
# Specify the byte range
188-
end_byte = start_byte + byte_count - 1
189-
headers = {"Range":"bytes=%d-%d" % (start_byte, end_byte),
190-
'Accept-Encoding': '*'}
191-
192187
# Get the content
193-
response = requests.get(url, headers=headers, stream=True)
194-
195-
# Raise HTTPError if invalid url
196-
response.raise_for_status()
188+
with _url.openurl(url, 'rb', buffering=0) as f:
189+
f.seek(start_byte)
190+
content = f.read(byte_count)
197191

198192
# Convert to numpy array
199-
sig_data = np.fromstring(response.content, dtype=dtype)
193+
sig_data = np.fromstring(content, dtype=dtype)
200194

201195
return sig_data
202196

0 commit comments

Comments
 (0)