Skip to content

Commit

Permalink
Fixed unique suffix placement for URLs with a file extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkbrzt committed Mar 4, 2013
1 parent 8e6c765 commit 7774eac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions httpie/downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def alter_request_headers(self, headers):
else:
self.bytes_resumed_from = self.bytes_downloaded = bytes_have
# Set ``Range`` header to resume the download
# TODO: detect Range support first?
headers['Range'] = '%d-' % bytes_have

def start(self, response):
Expand Down Expand Up @@ -132,18 +133,18 @@ def _get_unique_output_filename(self, url, content_type):

def _get_output_filename(self, url, content_type, suffix=None):

suffix = '' if not suffix else '-' + str(suffix)

fn = urlsplit(url).path.rstrip('/')
fn = os.path.basename(fn) if fn else 'index'

if suffix:
fn += '-' + str(suffix)

if '.' not in fn:
ext = mimetypes.guess_extension(content_type.split(';')[0])
if ext:
fn += ext
if '.' in fn:
base, ext = os.path.splitext(fn)
else:
base = fn
ext = mimetypes.guess_extension(content_type.split(';')[0]) or ''

return fn
return base + suffix + ext

def _on_progress(self, chunk):
"""
Expand Down
2 changes: 1 addition & 1 deletion httpie/humanize.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import doctest


def humanize_bytes(n, precision=1):
def humanize_bytes(n, precision=2):
"""Return a humanized string representation of a number of bytes.
Assumes `from __future__ import division`.
Expand Down

0 comments on commit 7774eac

Please sign in to comment.