# DownloadHandlerBuffer

> A general-purpose DownloadHandler implementation which stores received data in a native byte buffer.

## Definition

* **Type:** Class
* **Namespace:** [UnityEngine.Networking](/engine/6000.6/script-reference/unityengine/networking.md)
* **Assembly:** UnityEngine.UnityWebRequestModule
* **Inherits from:** [DownloadHandler](/engine/6000.6/script-reference/unityengine/networking/downloadhandler.md)
* **Implements:** [IDisposable](https://learn.microsoft.com/dotnet/api/system.idisposable)

```csharp
public sealed class DownloadHandlerBuffer : DownloadHandler, IDisposable
```

## Remarks

This is a general-purpose [DownloadHandler](/engine/6000.6/script-reference/unityengine/networking/downloadhandler.md) subclass. It stores received data in native memory. It preallocates a data buffer based on any received `Content-Length` header, but expands its buffer if the actual download size exceeds the value of the `Content-Length` header (or if a `Content-Length` header is not received).

**Note**: When accessing [DownloadHandler.data](/engine/6000.6/script-reference/unityengine/networking/downloadhandler/data.md) or [DownloadHandler.text](/engine/6000.6/script-reference/unityengine/networking/downloadhandler/text.md) on this subclass, a new byte array or string is allocated each time the property is accessed.

## Examples

```csharp
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;


public class MyBehaviour : MonoBehaviour {
    void Start() {
        StartCoroutine(GetText());
    }

    IEnumerator GetText() {
        UnityWebRequest www = new UnityWebRequest("https://www.my-server.com");
        www.downloadHandler = new DownloadHandlerBuffer();
        yield return www.SendWebRequest();

        if (www.result != UnityWebRequest.Result.Success) {
            Debug.Log(www.error);
        }
        else {
            // Show results as text
            Debug.Log(www.downloadHandler.text);

            // Or retrieve results as binary data
            byte[] results = www.downloadHandler.data;
        }
    }
}
```

## Constructors

| Constructor                                                                                                     | Description          |
| --------------------------------------------------------------------------------------------------------------- | -------------------- |
| [DownloadHandlerBuffer()](/engine/6000.6/script-reference/unityengine/networking/downloadhandlerbuffer/ctor.md) | Default constructor. |

## Static Methods

| Method                                                                                                   | Description                                                              |
| -------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------ |
| [GetContent](/engine/6000.6/script-reference/unityengine/networking/downloadhandlerbuffer/getcontent.md) | Returns a copy of the native-memory buffer interpreted as a UTF8 string. |

## Inheritance

**Inherited Members:**

* [DownloadHandler.Dispose()](/engine/6000.6/script-reference/unityengine/networking/downloadhandler/dispose.md)
* [DownloadHandler.isDone](/engine/6000.6/script-reference/unityengine/networking/downloadhandler/isdone.md)
* [DownloadHandler.error](/engine/6000.6/script-reference/unityengine/networking/downloadhandler/error.md)
* [DownloadHandler.nativeData](/engine/6000.6/script-reference/unityengine/networking/downloadhandler/nativedata.md)
* [DownloadHandler.data](/engine/6000.6/script-reference/unityengine/networking/downloadhandler/data.md)
* [DownloadHandler.text](/engine/6000.6/script-reference/unityengine/networking/downloadhandler/text.md)
