Small fixes to bugs in the streaming handler for use with magic and radosgw.

This commit is contained in:
Jake Moshenko 2014-09-09 18:30:14 -04:00
parent d2d51d15a2
commit c9e1648781
4 changed files with 25 additions and 13 deletions

View file

@ -7,23 +7,19 @@ import boto.gs.connection
import boto.s3.key
import boto.gs.key
from io import UnsupportedOperation, BufferedIOBase
from storage.basestorage import BaseStorage
logger = logging.getLogger(__name__)
class StreamReadKeyAsFile(object):
class StreamReadKeyAsFile(BufferedIOBase):
def __init__(self, key):
self._key = key
self._finished = False
def __enter__(self):
return self
def __exit__(self, type, value, tb):
self._key.close(fast=True)
def read(self, amt=None):
if self._finished:
return None
@ -33,6 +29,16 @@ class StreamReadKeyAsFile(object):
self._finished = True
return resp
def readable(self):
return True
@property
def closed(self):
return self._key.closed
def close(self):
self._key.close(fast=True)
class _CloudStorage(BaseStorage):
def __init__(self, connection_class, key_class, connect_kwargs, upload_params, storage_path,

View file

@ -1,5 +1,7 @@
import os
import shutil
import hashlib
import io
from storage.basestorage import BaseStorage
@ -39,7 +41,7 @@ class LocalStorage(BaseStorage):
def stream_read_file(self, path):
path = self._init_path(path)
return open(path, mode='rb')
return io.open(path, mode='rb')
def stream_write(self, path, fp, content_type=None):
# Size is mandatory