# ITableFileWriter

> Writes a table snapshot to a file, so a file-backed provider can ship its tables as data instead of assets.

## Definition

* **Type:** Interface
* **Namespace:** [Unity.Localization.Editor](/engine/6000.7/script-reference/unity/localization/editor.md)
* **Assembly:** UnityEditor

```csharp
public interface ITableFileWriter
```

## Remarks

A writer turns a [ResourceTableData](/engine/6000.7/script-reference/unity/localization/providers/filetables/resourcetabledata.md) snapshot into the bytes a matching [ITableFileReader](/engine/6000.7/script-reference/unity/localization/providers/filetables/itablefilereader.md) reads back at runtime. Writing runs in the editor when player data is generated, so no serialization code ships in a player. Pair an implementation with a [FileTableProviderEditor](/engine/6000.7/script-reference/unity/localization/editor/filetableprovidereditor.md) subclass to have Unity generate the files for a custom format.

Additional Resources: [FileTableProviderEditor](/engine/6000.7/script-reference/unity/localization/editor/filetableprovidereditor.md), [ITableFileReader](/engine/6000.7/script-reference/unity/localization/providers/filetables/itablefilereader.md), [ResourceTableData](/engine/6000.7/script-reference/unity/localization/providers/filetables/resourcetabledata.md)

Write a text format that the matching reader parses back.

## Examples

```csharp
using System.IO;
using System.Text;
using Unity.Localization.Editor;
using Unity.Localization.Providers.FileTables;

namespace Unity.Localization.Samples
{
    public class TextTableWriter : ITableFileWriter
    {
        public static readonly TextTableWriter Instance = new();

        public void Write(ResourceTableData data, Stream stream)
        {
            using var writer = new StreamWriter(stream, new UTF8Encoding(false), 1024, leaveOpen: true);
            writer.WriteLine($"@collection={data.CollectionName}");
            writer.WriteLine($"@guid={data.CollectionGuid}");
            writer.WriteLine($"@locale={data.LocaleCode}");
            foreach (var entry in data.Entries)
            {
                if (entry != null && !string.IsNullOrEmpty(entry.Key))
                    writer.WriteLine($"{entry.Key}={entry.Value}");
            }
        }
    }

    // Registering the editor for the provider type is what makes Unity generate the files at build time.
    [AssetProviderEditor(typeof(TextResourceProvider))]
    public class TextResourceProviderEditor : FileTableProviderEditor
    {
        public override ITableFileWriter Writer => TextTableWriter.Instance;
    }
}
```

## Methods

| Method                                                                                       | Description                          |
| -------------------------------------------------------------------------------------------- | ------------------------------------ |
| [Write](/engine/6000.7/script-reference/unity/localization/editor/itablefilewriter/write.md) | Writes a table snapshot to a stream. |
