github.com/Jeffail/benthos/v3@v3.65.0/website/docs/components/outputs/file.md (about) 1 --- 2 title: file 3 type: output 4 status: stable 5 categories: ["Local"] 6 --- 7 8 <!-- 9 THIS FILE IS AUTOGENERATED! 10 11 To make changes please edit the contents of: 12 lib/output/file.go 13 --> 14 15 import Tabs from '@theme/Tabs'; 16 import TabItem from '@theme/TabItem'; 17 18 19 Writes messages to files on disk based on a chosen codec. 20 21 ```yaml 22 # Config fields, showing default values 23 output: 24 label: "" 25 file: 26 path: "" 27 codec: lines 28 ``` 29 30 Messages can be written to different files by using [interpolation functions](/docs/configuration/interpolation#bloblang-queries) in the path field. However, only one file is ever open at a given time, and therefore when the path changes the previously open file is closed. 31 32 ## Batches and Multipart Messages 33 34 When writing multipart (batched) messages using the `lines` codec the last message ends with double delimiters. E.g. the messages "foo", "bar" and "baz" would be written as: 35 36 ``` 37 foo\n 38 bar\n 39 baz\n 40 ``` 41 42 Whereas a multipart message [ "foo", "bar", "baz" ] would be written as: 43 44 ``` 45 foo\n 46 bar\n 47 baz\n\n 48 ``` 49 50 This enables consumers of this output feed to reconstruct the original batches. However, if you wish to avoid this behaviour then add a [`split` processor](/docs/components/processors/split) before messages reach this output. 51 52 ## Fields 53 54 ### `path` 55 56 The file to write to, if the file does not yet exist it will be created. 57 This field supports [interpolation functions](/docs/configuration/interpolation#bloblang-queries). 58 59 60 Type: `string` 61 Default: `""` 62 Requires version 3.33.0 or newer 63 64 ```yaml 65 # Examples 66 67 path: /tmp/data.txt 68 69 path: /tmp/${! timestamp_unix() }.txt 70 71 path: /tmp/${! json("document.id") }.json 72 ``` 73 74 ### `codec` 75 76 The way in which the bytes of messages should be written out into the output data stream. It's possible to write lines using a custom delimiter with the `delim:x` codec, where x is the character sequence custom delimiter. 77 78 79 Type: `string` 80 Default: `"lines"` 81 Requires version 3.33.0 or newer 82 83 | Option | Summary | 84 |---|---| 85 | `all-bytes` | Only applicable to file based outputs. Writes each message to a file in full, if the file already exists the old content is deleted. | 86 | `append` | Append each message to the output stream without any delimiter or special encoding. | 87 | `lines` | Append each message to the output stream followed by a line break. | 88 | `delim:x` | Append each message to the output stream followed by a custom delimiter. | 89 90 91 ```yaml 92 # Examples 93 94 codec: lines 95 96 codec: "delim:\t" 97 98 codec: delim:foobar 99 ``` 100 101