Skip to content

Commit 4992796

Browse files
author
Ong Yong Xin
authored
Allow curl to download binary blobs
Files to be downloaded could contain binary or Unicode symbols, so contents of downloaded file should be written directly as bytes.
1 parent a56f686 commit 4992796

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

bin/curl.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ def main(args):
7575
return
7676

7777
if ns.output_file:
78-
with open(ns.output_file, 'w') as outs:
79-
outs.write(r.text)
78+
with open(ns.output_file, 'wb') as outs:
79+
outs.write(r.content)
8080
elif ns.remote_name:
8181
# get basename of url
8282
url_path = urlparse(url).path
8383
filename = url_path.split('/')[-1]
84-
with open(filename, 'w') as outs:
85-
outs.write(r.text)
84+
with open(filename, 'wb') as outs:
85+
outs.write(r.content)
8686
else:
8787
print(r.text)
8888

0 commit comments

Comments
 (0)