# Class ObjectRewriter (3.7.0-rc)

3.7.0-rc 3.6.0 (latest) 3.5.0 3.4.0 3.3.0 3.2.0 2.48.0-rc 2.47.1 2.46.0 2.45.0 2.44.0 2.43.0 2.42.0 2.41.0 2.40.0 2.39.0 2.38.0 2.37.0 2.36.0 2.35.0 2.34.0 2.33.0 2.32.0 2.31.0 2.30.0 2.29.0 2.28.0 2.27.0 2.26.0 2.25.1 2.24.0 2.23.0 2.22.1 2.21.0 2.20.0 2.19.0 2.18.0 2.17.0 2.16.0 2.15.1 2.14.0 2.13.0 2.12.0 2.11.0 Complete long running object rewrite operations.
The [`Client::RewriteObject()`](https://docs.cloud.google.com/cpp/docs/reference/storage/latest/classgoogle_1_1cloud_1_1storage_1_1Client#classgoogle_1_1cloud_1_1storage_1_1Client_1a848ddd3d08e9c24e0c1bc31da53a8b10) operation allows applications to copy objects across location boundaries, and to rewrite objects with different encryption keys. In some circumstances it may take multiple calls to the service to complete a rewrite, this class encapsulates the state of a partial copy.

## Constructors

### ObjectRewriter(std::shared_ptr\< internal::StorageConnection \>, internal::RewriteObjectRequest)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `connection` | `std::shared_ptr< internal::StorageConnection >` |
| `request` | `internal::RewriteObjectRequest` |

## Functions

### Iterate()

Perform one iteration in the rewrite.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `StatusOr< RewriteProgress >` | The progress after the iteration. If the rewrite has completed the application can use [`Result()`](https://docs.cloud.google.com/cpp/docs/reference/storage/latest/classgoogle_1_1cloud_1_1storage_1_1ObjectRewriter#classgoogle_1_1cloud_1_1storage_1_1ObjectRewriter_1ab7752e3a32913c2c1e520a4b7857222d) to examine the metadata for the newly created object. |

### CurrentProgress() const

The current progress on the rewrite operation.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `StatusOr< RewriteProgress >` |   |

### Result()

Iterate until the operation completes using a callback to report progress.

> [!NOTE]
> **Note:** This operation blocks until the copy is finished. For very large objects that could take substantial time. Applications may need to persist the rewrite operation. Some applications may want to wrap this call with `std::async`, and run the copy on a separate thread.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `StatusOr< ObjectMetadata >` | the object metadata once the copy completes. |

### ResultWithProgressCallback(Functor)

Iterate until the operation completes using a callback to report progress.

> [!NOTE]
> **Note:** This operation blocks until the copy is finished. For very large objects that could take substantial time. Applications may need to persist the rewrite operation. Some applications may want to wrap this call with `std::async`, and run the copy on a separate thread.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `cb` | `Functor` the callback object. |
| `typename Functor` | the type of the callback object. It must satisfy: `std:is_invocable<Functor,`[`StatusOr`](https://docs.cloud.google.com/cpp/docs/reference/common/latest/classgoogle_1_1cloud_1_1StatusOr.html)`<`[`RewriteProgress`](https://docs.cloud.google.com/cpp/docs/reference/storage/latest/structgoogle_1_1cloud_1_1storage_1_1RewriteProgress)`>>:: value == true`. |
| `std::enable_if_t<>< functor,="">` |   |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `StatusOr< ObjectMetadata >` | the object metadata once the copy completes. |

### token() const

The current rewrite token.
Applications can save the token of partially completed rewrites, and restart those operations using `Client::CopyObjectRestart`, even if the application has terminated. It is up to the application to preserve all the other information for the request, including source and destination buckets, encryption keys, and any preconditions affecting the request.

> [!NOTE]
> **Note:** For rewrites that have not started the token is an empty string. For rewrites that have completed the token is also an empty string. The application should preserve other information (such as the [`RewriteProgress`](https://docs.cloud.google.com/cpp/docs/reference/storage/latest/structgoogle_1_1cloud_1_1storage_1_1RewriteProgress)) to avoid repeating a rewrite.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `std::string const &` |   |