fix when there is no gallery dir
[redakcja.git] / apps / dvcs / storage.py
1 # -*- coding: utf-8 -*-
2 from zlib import compress, decompress
3
4 from django.core.files.base import ContentFile
5 from django.core.files.storage import FileSystemStorage
6
7
8 class GzipFileSystemStorage(FileSystemStorage):
9     def _open(self, name, mode='rb'):
10         """TODO: This is good for reading; what about writing?"""
11         f = open(self.path(name), 'rb')
12         text = f.read()
13         f.close()
14         return ContentFile(decompress(text))
15
16     def _save(self, name, content):
17         content = ContentFile(compress(content.read()))
18
19         return super(GzipFileSystemStorage, self)._save(name, content)