aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/storage/filestorage.py
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/storage/filestorage.py')
-rw-r--r--mediagoblin/storage/filestorage.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/mediagoblin/storage/filestorage.py b/mediagoblin/storage/filestorage.py
index 29b8383b..89f43276 100644
--- a/mediagoblin/storage/filestorage.py
+++ b/mediagoblin/storage/filestorage.py
@@ -14,14 +14,25 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+import io
+import os
+import shutil
+
+import six.moves.urllib.parse as urlparse
+
from mediagoblin.storage import (
StorageInterface,
clean_listy_filepath,
NoWebServing)
-import os
-import shutil
-import urlparse
+class FileObjectAwareFile(io.FileIO):
+ def write(self, data):
+ if hasattr(data, 'read'):
+ # We can call data.read(). It means that the data is a file-like
+ # object, which should be saved RAM-friendly way
+ shutil.copyfileobj(data, self)
+ else:
+ super(FileObjectAwareFile, self).write(data)
class BasicFileStorage(StorageInterface):
@@ -59,7 +70,7 @@ class BasicFileStorage(StorageInterface):
os.makedirs(directory)
# Grab and return the file in the mode specified
- return open(self._resolve_filepath(filepath), mode)
+ return FileObjectAwareFile(self._resolve_filepath(filepath), mode)
def delete_file(self, filepath):
"""Delete file at filepath