# save

The `save` statement is used to write the contents of a [named buffer](/2.10.2/data-pipelines/extract/language/buffer.md) to disk.

## Syntax

**`save`***`{buffer_name}`***`as`***`filename`*

## Details

The `save` statement will write the contents of a [named buffer](/2.10.2/data-pipelines/extract/language/buffer.md) to *filename*. As well as providing a means of direct-to-disk downloading this can be useful for retrieving server responses and capturing them for later examination, whether it be for analysis, debugging or audit purposes.

If the destination file already exists then it will be overwritten.

If the *filename* argument contains a path component, then any directories not present in the path will be created. If creation of the path destination file is not successful then an error will be logged and the USE script will fail.

The `save` statement is similar in effect to the [http\_savefile](https://github.com/exivity/docs/tree/60a265079e19e329e990b94f7836ea2024c5f214/extract/language/set/README.md#http_savefile.md) option supported by [set](/2.10.2/data-pipelines/extract/language/set.md), in that data from a server is written to disk. There is one important distinction however:

* When [set http\_savefile](/2.10.2/data-pipelines/extract/language/set.md) has been used to specify a file to save, the next [HTTP](/2.10.2/data-pipelines/extract/language/http.md) request will stream data to the file as it is received from the server
* When a [buffer](/2.10.2/data-pipelines/extract/language/buffer.md) statement is used to capture the server response, and a subsequent `save` statement is used to write it to disk, all the buffered data will be written to the file immediately

## Example

```
var server = "https://my_json_server.com"
buffer response = http GET ${server}/generatetoken        

# Save a copy of the original server response for diagnostic purposes
save {response} as "${baseDir}\diagnostics\token.json"

# Create a variable called ${secret_token} from the 'access_token'
# string in the JSON in the {response} buffer
var secret_token = $JSON{response}.[access_token]

# We no longer need the {response} buffer as the value extracted
# from it is stored in a variable
discard {response}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://olddocs.exivity.io/2.10.2/data-pipelines/extract/language/save.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
