Repository: gtsystem/python-remotezip

Issue:
feature request: file size of remote zip file
Unfortunatelly summing up all uncompressed sizes of all zipped entries is not equivalent to the filesize if I were to download a zip file. I guess thats because the zip file itself has metadata etc.
Therefore, I would like to store the file size of the remote file and make it available to the RemoteZip class. I think this should be the output of `RemoteFetcher.get_file_size()`?

Discussion:

Patch:
diff --git a/remotezip.py b/remotezip.py
index a0a994c..f7302f0 100755
--- a/remotezip.py
+++ b/remotezip.py
@@ -5,7 +5,6 @@ from datetime import datetime
 from itertools import tee
 
 import requests
-from tabulate import tabulate
 
 __all__ = ['RemoteIOError', 'RemoteZip']
 
@@ -254,17 +253,35 @@ class RemoteZip(zipfile.ZipFile):
         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):
diff --git a/setup.py b/setup.py
index 9cf96ac..65c94d4 100644
--- a/setup.py
+++ b/setup.py
@@ -5,7 +5,7 @@ with open("README.md") as f:
 
 setup(
     name='remotezip',
-    version='0.12.2',
+    version='0.12.3',
     author='Giuseppe Tribulato',
     author_email='gtsystem@gmail.com',
     py_modules=['remotezip'],
@@ -14,7 +14,7 @@ setup(
     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"],
     },


Test patch:
diff --git a/test_remotezip.py b/test_remotezip.py
index 03e006d..186a055 100644
--- a/test_remotezip.py
+++ b/test_remotezip.py
@@ -338,6 +338,7 @@ class TestRemoteZip(unittest.TestCase):
 
     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())