# ITableFileReader

> Reads a table snapshot from a file at runtime, so a file-backed provider can rebuild a table without shipping the authored table asset.

## Definition

* **Type:** Interface
* **Namespace:** [Unity.Localization.Providers.FileTables](/engine/6000.7/script-reference/unity/localization/providers/filetables.md)
* **Assembly:** UnityEngine.LocalizationRuntimeModule

```csharp
public interface ITableFileReader
```

## Remarks

A reader turns a stream into a [ResourceTableData](/engine/6000.7/script-reference/unity/localization/providers/filetables/resourcetabledata.md) snapshot, which the provider rebuilds into a table. Writing the snapshot lives on the editor side, so no serialization code ships in a player. Implement this and pair it with a [FileTableProvider](/engine/6000.7/script-reference/unity/localization/providers/filetables/filetableprovider.md) subclass to add a runtime table format; [JsonResourceProvider](/engine/6000.7/script-reference/unity/localization/providers/filetables/jsonresourceprovider.md) pairs the default [JsonTableReader](/engine/6000.7/script-reference/unity/localization/providers/filetables/jsontablereader.md) for JSON.

Additional Resources: [FileTableProvider](/engine/6000.7/script-reference/unity/localization/providers/filetables/filetableprovider.md), [JsonTableReader](/engine/6000.7/script-reference/unity/localization/providers/filetables/jsontablereader.md), [ResourceTableData](/engine/6000.7/script-reference/unity/localization/providers/filetables/resourcetabledata.md)

Add a runtime table format by pairing a reader with a provider.

## Examples

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

namespace Unity.Localization.Samples
{
    // Deliberately simple: one "key=value" line per entry, so a key cannot hold '=' and a value cannot span lines.
    public class TextTableReader : ITableFileReader
    {
        public const string Extension = "txt";
        public static readonly TextTableReader Instance = new();

        public string FileExtension => Extension;

        public ResourceTableData Read(Stream stream)
        {
            var data = new ResourceTableData();
            using var reader = new StreamReader(stream, Encoding.UTF8, true, 1024, leaveOpen: true);
            while (reader.ReadLine() is { } line)
            {
                if (line.StartsWith("#", StringComparison.Ordinal))
                    continue;
                var split = line.IndexOf('=');
                if (split <= 0)
                    continue;
                var key = line[..split].Trim();
                var value = line[(split + 1)..].Trim();
                switch (key)
                {
                    case "@collection":
                        data.CollectionName = value;
                        break;
                    case "@guid":
                        data.CollectionGuid = value;
                        break;
                    case "@locale":
                        data.LocaleCode = value;
                        break;
                    default:
                        // No id in the file, so the shared data assigns one and matches the row by key.
                        data.Entries.Add(new EntryData { Key = key, Value = value });
                        break;
                }
            }
            return data;
        }
    }

    [Serializable]
    public class TextResourceProvider : FileTableProvider
    {
        protected override ITableFileReader Reader => TextTableReader.Instance;

        // A language is discovered from the file name, so adding one means writing a file beside the others.
        public static string LanguageFilePath(string dataFolder, string collectionName, string localeCode)
            => Path.Combine(dataFolder, FileName(collectionName, localeCode, TextTableReader.Extension));
    }
}
```

## Properties

| Property                                                                                                                   | Description                                                  |
| -------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------ |
| [FileExtension](/engine/6000.7/script-reference/unity/localization/providers/filetables/itablefilereader/fileextension.md) | The file extension the format uses, without the leading dot. |

## Methods

| Method                                                                                                   | Description                           |
| -------------------------------------------------------------------------------------------------------- | ------------------------------------- |
| [Read](/engine/6000.7/script-reference/unity/localization/providers/filetables/itablefilereader/read.md) | Reads a table snapshot from a stream. |
