1 from __future__ import unicode_literals
4 from django.core.files.base import ContentFile, File
5 from django.core.files.storage import FileSystemStorage
8 from gzip import compress, decompress
11 from gzip import GzipFile
12 from StringIO import StringIO
15 compressed = StringIO()
16 GzipFile(fileobj=compressed, mode="wb").write(data)
17 return compressed.getvalue()
20 return GzipFile(fileobj=StringIO(data)).read()
23 class GzipFileSystemStorage(FileSystemStorage):
24 def _open(self, name, mode='rb'):
25 """TODO: This is good for reading; what about writing?"""
26 f = open(self.path(name), 'rb')
29 return ContentFile(decompress(text))
31 def _save(self, name, content):
32 content = ContentFile(compress(content.read()))
33 return super(GzipFileSystemStorage, self)._save(name, content)
35 def get_available_name(self, name):