---
title: "Read concatenated TAR archives in C#"
url: https://recursiveai.org/onearchive/cookbook/read-concatenated-tar-archives/
description: "List entries from two TAR archives joined end to end in C#. Set IgnoreZeroBlocks to keep reading past the first archive’s end marker with OneArchive."
version: "1.2.0"
---

# Read concatenated TAR archives in C#

**OneArchive** is a free, open-source archive and compression library for .NET from Recursive AI: zip, tar, 7z, RAR and more in RecursiveAI.OneArchive, with compression codecs in RecursiveAI.OneCompress. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneArchive) · [GitHub](https://github.com/recursive-ai-oss/onearchive-csharp) · [Docs](https://recursiveai.org/onearchive/docs/) · [Download example (.zip)](https://recursiveai.org/onearchive/cookbook/read-concatenated-tar-archives/read-concatenated-tar-archives.zip)

Set `IgnoreZeroBlocks` to read both TARs in the download’s `joined.tar`.

```shell
dotnet add package RecursiveAI.OneArchive
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using RecursiveAI.OneArchive.Tar;

using var input = File.OpenRead(
    "joined.tar");
using var tar = new TarReader(input,
    new() { IgnoreZeroBlocks = true });
while (tar.GetNextEntry() is { } entry)
    Console.WriteLine(entry.Name);
```

Prints one entry from each archive, in stream order:

```text
a.txt
b.txt
```

Unzip [the example](https://recursiveai.org/onearchive/cookbook/read-concatenated-tar-archives/read-concatenated-tar-archives.zip), then `dotnet run`.

The download’s first TAR contains `a.txt` (`Alpha`), and the second contains `b.txt` (`Beta`). Both text files end in a newline. If you get only `a.txt`, make sure you passed `IgnoreZeroBlocks = true` to the `TarReader` you’re using.

To join your own plain TAR files, run `cat a.tar b.tar > joined.tar` on Linux or macOS, or `copy /b a.tar+b.tar joined.tar` in Windows Command Prompt.

## Variations

**Stop at the first end marker.** In the snippet at the top, replace the reader construction with this to see the default behavior:

```csharp
using var tar = new TarReader(input);
```

```text
a.txt
```

## Related recipes

- [Create a plain TAR archive](https://recursiveai.org/onearchive/cookbook/create-tar-archive/)
- [Extract a tar.gz file](https://recursiveai.org/onearchive/cookbook/extract-tar-gz/)

## The short answer

Open the joined TAR stream with `TarReader`, set `TarReaderOptions.IgnoreZeroBlocks` to `true`, and call `GetNextEntry()` until it returns `null`. The reader skips the zero blocks that normally mark the end of a TAR and reaches the headers in the next one. It lists entries in stream order and doesn’t extract them.

## Why does TAR stop after the first archive?

A TAR writer normally ends the archive with two 512-byte zero blocks and can add more zero padding to fill out a record. OneArchive’s default reader stops at the first zero block at a header position. If you simply append a second complete TAR, you leave that first end marker in the middle of the new file. There’s nothing wrong with the second TAR; the reader has already stopped before it gets there.

`IgnoreZeroBlocks` changes how the reader treats blocks where it expects the next header. It doesn’t remove zero bytes from file data or treat duplicate paths as one entry. If both source archives contain `notes.txt`, both entries can appear. Decide which one you need before using the listing to drive an extraction workflow.

## Can I use the same option for a TAR with no end marker?

Yes, but choose the option that describes the file you have. `IgnoreZeroBlocks` is for reading past zero blocks and also makes `RequireEndOfArchive` irrelevant. If you have a single TAR that stops cleanly between entries without an end marker, set `RequireEndOfArchive = false` instead. With `IgnoreZeroBlocks` off, that still stops at a zero block if one is present. Neither option repairs a partial header or missing file data. See [the TAR reader’s end-of-archive rules](https://recursiveai.org/onearchive/docs/archive/#reading) for how it handles these cases.
