Ejemplo n.º 1
0
    def __init__(self,
                 client,
                 path,
                 mode='w',
                 mime_type='application/octet-stream'):
        self.client = client
        self.path = path
        self.mode = mode
        self.bucket, self.name = parse_gcs_path(path)

        self.closed = False
        self.position = 0

        # A small buffer to avoid CPU-heavy per-write pipe calls.
        self.write_buffer = bytearray()
        self.write_buffer_size = 128 * 1024

        # Set up communication with uploading thread.
        parent_conn, child_conn = multiprocessing.Pipe()
        self.child_conn = child_conn
        self.conn = parent_conn

        # Set up uploader.
        self.insert_request = (storage.StorageObjectsInsertRequest(
            bucket=self.bucket, name=self.name))
        self.upload = transfer.Upload(GcsBufferedWriter.PipeStream(child_conn),
                                      mime_type,
                                      chunksize=WRITE_CHUNK_SIZE)
        self.upload.strategy = transfer.RESUMABLE_UPLOAD

        # Start uploading thread.
        self.upload_thread = threading.Thread(target=self._start_upload)
        self.upload_thread.daemon = True
        self.upload_thread.last_error = None
        self.upload_thread.start()
Ejemplo n.º 2
0
  def __init__(self, client, path, mime_type):
    self._client = client
    self._path = path
    self._bucket, self._name = parse_gcs_path(path)
    self._mime_type = mime_type

    # Set up communication with child thread.
    parent_conn, child_conn = multiprocessing.Pipe()
    self._child_conn = child_conn
    self._conn = parent_conn

    # Set up uploader.
    self._insert_request = (storage.StorageObjectsInsertRequest(
        bucket=self._bucket, name=self._name))
    self._upload = transfer.Upload(
        PipeStream(self._child_conn),
        self._mime_type,
        chunksize=WRITE_CHUNK_SIZE)
    self._upload.strategy = transfer.RESUMABLE_UPLOAD

    # Start uploading thread.
    self._upload_thread = threading.Thread(target=self._start_upload)
    self._upload_thread.daemon = True
    self._upload_thread.last_error = None
    self._upload_thread.start()
Ejemplo n.º 3
0
    def __init__(self, client, path, mime_type='application/octet-stream'):
        self.client = client
        self.path = path
        self.bucket, self.name = parse_gcs_path(path)

        self.closed = False
        self.position = 0

        # Set up communication with uploading thread.
        parent_conn, child_conn = multiprocessing.Pipe()
        self.conn = parent_conn

        # Set up uploader.
        self.insert_request = (storage.StorageObjectsInsertRequest(
            bucket=self.bucket, name=self.name))
        self.upload = transfer.Upload(GcsBufferedWriter.PipeStream(child_conn),
                                      mime_type)
        self.upload.strategy = transfer.RESUMABLE_UPLOAD

        # Start uploading thread.
        self.upload_thread = threading.Thread(target=self._start_upload)
        self.upload_thread.daemon = True
        self.upload_thread.start()