hfaran / slack-export-viewer

A Slack Export archive viewer that allows you to easily view and share your Slack team's export
https://pypi.python.org/pypi/slack-export-viewer
MIT License
951 stars 192 forks source link

Uses up all the memory on the host and then fails #83

Closed jakubgs closed 5 years ago

jakubgs commented 6 years ago

I tried using this but it just sucks up all the memory available and then fails. I don't see how this is usable.

hfaran commented 5 years ago

It's possible that the archive you're trying to load is too large and the tool fails trying to load and render everything in memory. Something like #73 might help with if it gets implemented.

vweevers commented 5 years ago

I didn't have the time to fully test this, but the following patch fixed things for me:

diff --git a/slackviewer/archive.py b/slackviewer/archive.py
index 39a829e..86d9209 100644
--- a/slackviewer/archive.py
+++ b/slackviewer/archive.py
@@ -23,8 +23,15 @@ def SHA1_file(filepath, extra=""):
     :rtype: str
     """

+    h = hashlib.sha1()
     with io.open(filepath, 'rb') as f:
-        return hashlib.sha1(f.read() + extra).hexdigest()
+        while True:
+            data = f.read(2**20)
+            if not data:
+                break
+            h.update(data)
+    h.update(extra)
+    return h.hexdigest()

 def extract_archive(filepath):

Instead of putting the whole archive in memory, it reads it chunk by chunk. If someone wants to make a PR of this, feel free.

hfaran commented 5 years ago

Thanks @vweevers! I just merged a variant of this solution. @jakubgs let us know if that helps.