mirror of
https://github.com/httpie/cli.git
synced 2024-11-08 00:44:45 +01:00
Fixed unique suffix placement for URLs with a file extension.
This commit is contained in:
parent
8e6c765be2
commit
7774eac3df
@ -63,6 +63,7 @@ class Download(object):
|
|||||||
else:
|
else:
|
||||||
self.bytes_resumed_from = self.bytes_downloaded = bytes_have
|
self.bytes_resumed_from = self.bytes_downloaded = bytes_have
|
||||||
# Set ``Range`` header to resume the download
|
# Set ``Range`` header to resume the download
|
||||||
|
# TODO: detect Range support first?
|
||||||
headers['Range'] = '%d-' % bytes_have
|
headers['Range'] = '%d-' % bytes_have
|
||||||
|
|
||||||
def start(self, response):
|
def start(self, response):
|
||||||
@ -132,18 +133,18 @@ class Download(object):
|
|||||||
|
|
||||||
def _get_output_filename(self, url, content_type, suffix=None):
|
def _get_output_filename(self, url, content_type, suffix=None):
|
||||||
|
|
||||||
|
suffix = '' if not suffix else '-' + str(suffix)
|
||||||
|
|
||||||
fn = urlsplit(url).path.rstrip('/')
|
fn = urlsplit(url).path.rstrip('/')
|
||||||
fn = os.path.basename(fn) if fn else 'index'
|
fn = os.path.basename(fn) if fn else 'index'
|
||||||
|
|
||||||
if suffix:
|
if '.' in fn:
|
||||||
fn += '-' + str(suffix)
|
base, ext = os.path.splitext(fn)
|
||||||
|
else:
|
||||||
|
base = fn
|
||||||
|
ext = mimetypes.guess_extension(content_type.split(';')[0]) or ''
|
||||||
|
|
||||||
if '.' not in fn:
|
return base + suffix + ext
|
||||||
ext = mimetypes.guess_extension(content_type.split(';')[0])
|
|
||||||
if ext:
|
|
||||||
fn += ext
|
|
||||||
|
|
||||||
return fn
|
|
||||||
|
|
||||||
def _on_progress(self, chunk):
|
def _on_progress(self, chunk):
|
||||||
"""
|
"""
|
||||||
|
@ -7,7 +7,7 @@ URL: http://code.activestate.com/recipes/577081/
|
|||||||
import doctest
|
import doctest
|
||||||
|
|
||||||
|
|
||||||
def humanize_bytes(n, precision=1):
|
def humanize_bytes(n, precision=2):
|
||||||
"""Return a humanized string representation of a number of bytes.
|
"""Return a humanized string representation of a number of bytes.
|
||||||
|
|
||||||
Assumes `from __future__ import division`.
|
Assumes `from __future__ import division`.
|
||||||
|
Loading…
Reference in New Issue
Block a user