X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/5ef8e304790026b27417d8ff3c76c18858ba708f..73ef2b8442dc95f8b7279de812c30ac8626d5f39:/apps/dvcs/storage.py?ds=inline diff --git a/apps/dvcs/storage.py b/apps/dvcs/storage.py new file mode 100755 index 00000000..6bb5b595 --- /dev/null +++ b/apps/dvcs/storage.py @@ -0,0 +1,18 @@ +from zlib import compress, decompress + +from django.core.files.base import ContentFile, File +from django.core.files.storage import FileSystemStorage + + +class GzipFileSystemStorage(FileSystemStorage): + def _open(self, name, mode='rb'): + """TODO: This is good for reading; what about writing?""" + f = open(self.path(name), 'rb') + text = f.read() + f.close() + return ContentFile(decompress(text)) + + def _save(self, name, content): + content = ContentFile(compress(content.read())) + + return super(GzipFileSystemStorage, self)._save(name, content)