Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions remotezip.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from itertools import tee

import requests
from tabulate import tabulate

__all__ = ['RemoteIOError', 'RemoteZip']

Expand Down Expand Up @@ -254,17 +253,35 @@ def _get_position_to_size(self):
ilist.append(self.start_dir)
return {a: b-a for a, b in pairwise(ilist)}

def size(self):
return self.fp._file_size if self.fp else 0


def _list_files(url, support_suffix_range, filenames):
with RemoteZip(url, headers={'User-Agent': 'remotezip'}, support_suffix_range=support_suffix_range) as zip:
if len(filenames) == 0:
filenames = zip.namelist()
data = [('Length', 'DateTime', 'Name')]
data = []
for fname in filenames:
zinfo = zip.getinfo(fname)
dt = datetime(*zinfo.date_time)
data.append((zinfo.file_size, dt.strftime('%Y-%m-%d %H:%M:%S'), zinfo.filename))
print(tabulate(data, headers='firstrow'))
_printTable(data, ('Length', 'DateTime', 'Name'), '><<')


def _printTable(data, header, align):
# get max col width & prepare formatting string
col_w = [len(col) for col in header]
for row in data:
col_w = [max(w, len(str(x))) for w, x in zip(col_w, row)]
fmt = ' '.join('{{:{}{}}}'.format(a, w)
for w, a in zip(col_w, align + '<' * 99))
# print table
print(fmt.format(*header).rstrip())
print(fmt.format(*['-' * w for w in col_w]))
for row in data:
print(fmt.format(*row).rstrip())
print()


def _extract_files(url, support_suffix_range, filenames, path):
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='remotezip',
version='0.12.2',
version='0.12.3',
author='Giuseppe Tribulato',
author_email='[email protected]',
py_modules=['remotezip'],
Expand All @@ -14,7 +14,7 @@
description='Access zip file content hosted remotely without downloading the full file.',
long_description=description,
long_description_content_type="text/markdown",
install_requires=["requests", "tabulate"],
install_requires=["requests"],
extras_require={
"test": ["requests_mock"],
},
Expand Down
1 change: 1 addition & 0 deletions test_remotezip.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ def test_interface(self):

def test_zip64(self):
zfile = rz.RemoteZip('test_data/zip64.zip', fetcher=LocalFetcher)
self.assertEqual(zfile.size(), 1167)
self.assertEqual(zfile.read('big_file'), b'\x00' * (1024*1024))
self.assertIsNone(zfile.testzip())

Expand Down