1 # This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 from zlib import compress, decompress
6 from django.core.files.base import ContentFile, File
7 from django.core.files.storage import FileSystemStorage
8 from django.utils.deconstruct import deconstructible
9 from django.utils.encoding import force_bytes
13 class GzipFileSystemStorage(FileSystemStorage):
14 def _open(self, name, mode='rb'):
15 """TODO: This is good for reading; what about writing?"""
16 f = open(self.path(name), 'rb')
19 return ContentFile(decompress(text))
21 def _save(self, name, content):
22 data = force_bytes(content.read())
23 content = ContentFile(compress(data))
25 return super(GzipFileSystemStorage, self)._save(name, content)