91f78e6013a32b7a28573d20fbd84bd615faf499
[redakcja.git] / src / dvcs / storage.py
1 from zlib import compress, decompress
2
3 from django.core.files.base import ContentFile, File
4 from django.core.files.storage import FileSystemStorage
5 from django.utils.deconstruct import deconstructible
6
7
8 @deconstructible
9 class GzipFileSystemStorage(FileSystemStorage):
10     def _open(self, name, mode='rb'):
11         """TODO: This is good for reading; what about writing?"""
12         f = open(self.path(name), 'rb')
13         text = f.read()
14         f.close()
15         return ContentFile(decompress(text))
16
17     def _save(self, name, content):
18         content = ContentFile(compress(content.read()))
19
20         return super(GzipFileSystemStorage, self)._save(name, content)