Ejemplo n.º 1
0
 def read_backblaze_meta_chunk(self,
                               req,
                               storage_method,
                               meta_chunk,
                               meta_start=None,
                               meta_end=None):
     container_id = safe_get_header(req, 'container_id')
     sysmeta = {'container_id': container_id}
     key_file = self.conf.get('key_file')
     try:
         creds = BackblazeUtils.get_credentials(storage_method, key_file)
     except ConfigurationException as exc:
         return Response(exc, 500)
     if meta_start is not None:
         if meta_start < 0:
             offset = meta_start
             size = -meta_start
         elif meta_end is not None:
             offset = meta_start
             size = meta_end - meta_start + 1
         else:
             offset = meta_start
             size = None
     elif meta_end is not None:
         offset = 0
         size = meta_end + 1
     handler = BackblazeChunkDownloadHandler(sysmeta, meta_chunk, offset,
                                             size, None, creds)
     stream = handler.get_stream()
     return Response(stream, 200)
Ejemplo n.º 2
0
    def _fetch_stream_backblaze(self, meta, chunks, ranges, storage_method, key_file):
        backblaze_info = self._b2_credentials(storage_method, key_file)
        total_bytes = 0
        current_offset = 0
        size = None
        offset = 0
        for pos in range(len(chunks)):
            if ranges:
                offset = ranges[pos][0]
                size = ranges[pos][1]

            if size is None:
                size = int(meta["length"])
            chunk_size = int(chunks[pos][0]["size"])
            if total_bytes >= size:
                break
            if current_offset + chunk_size > offset:
                if current_offset < offset:
                    _offset = offset - current_offset
                else:
                    _offset = 0
                if chunk_size + total_bytes > size:
                    _size = size - total_bytes
                else:
                    _size = chunk_size
            handler = BackblazeChunkDownloadHandler(meta, chunks[pos], _offset, _size, backblaze_info=backblaze_info)
            stream = handler.get_stream()
            if not stream:
                raise exc.OioException("Error while downloading")
            total_bytes += len(stream)
            yield stream
            current_offset += chunk_size
Ejemplo n.º 3
0
 def read_backblaze_meta_chunk(self, req, storage_method, meta_chunk,
                               meta_start=None, meta_end=None):
     container_id = req.headers[sys_headers['container_id']]
     sysmeta = {'container_id': container_id}
     key_file = self.conf.get('key_file')
     try:
         creds = BackblazeUtils.get_credentials(storage_method, key_file)
     except BackblazeUtilsException as exc:
         return Response(exc, 500)
     if meta_start is not None:
         if meta_start < 0:
             offset = meta_start
             size = -meta_start
         elif meta_end is not None:
             offset = meta_start
             size = meta_end - meta_start + 1
         else:
             offset = meta_start
             size = None
     elif meta_end is not None:
         offset = 0
         size = meta_end + 1
     handler = BackblazeChunkDownloadHandler(sysmeta, meta_chunk,
                                             offset, size,
                                             None, creds)
     stream = handler.get_stream()
     return Response(stream, 200)
Ejemplo n.º 4
0
    def _fetch_stream_backblaze(self, meta, chunks, ranges,
                                storage_method, key_file):
        backblaze_info = self._b2_credentials(storage_method, key_file)
        total_bytes = 0
        current_offset = 0
        size = None
        offset = 0
        for pos in range(len(chunks)):
            if ranges:
                offset = ranges[pos][0]
                size = ranges[pos][1]

            if size is None:
                size = int(meta["length"])
            chunk_size = int(chunks[pos][0]["size"])
            if total_bytes >= size:
                break
            if current_offset + chunk_size > offset:
                if current_offset < offset:
                    _offset = offset - current_offset
                else:
                    _offset = 0
                if chunk_size + total_bytes > size:
                    _size = size - total_bytes
                else:
                    _size = chunk_size
            handler = BackblazeChunkDownloadHandler(
                meta, chunks[pos], _offset, _size,
                backblaze_info=backblaze_info)
            stream = handler.get_stream()
            if not stream:
                raise exc.OioException("Error while downloading")
            total_bytes += len(stream)
            yield stream
            current_offset += chunk_size