1 # -*- coding: utf-8 -*-
2 from zlib import compress, decompress
4 from django.core.files.base import ContentFile
5 from django.core.files.storage import FileSystemStorage
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')
14 return ContentFile(decompress(text))
16 def _save(self, name, content):
17 content = ContentFile(compress(content.read()))
19 return super(GzipFileSystemStorage, self)._save(name, content)