Skip to content

A very fast CSV parser. Has a ton of features and is easily configurable via a fluent API.

Notifications You must be signed in to change notification settings

Phylum123/RocketCsv

Repository files navigation

A very fast Csv parser. Tons of features and a very easy to configure fluent API.

Installation

Use Nuget to get references to packages: RocketCsv & RocketCsv.SourceGenerator

Basic Configuration

Given the class below:

public class User
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Location { get; set; }
    public string Email { get; set; }
}

And a csv file that looks like this:

id, name, location, email
0, "User0", "Location0", "Email0@email.com"
1, "User1", "Location1", "Email1@email.com"
2, "User2", "Location2", "Email2@email.com"
3, "User3", "Location3", "Email3@email.com"

You simply create a csv map by inheriting from CsvMapBase and marking it with the [CsvMap] attribute. You are now ready to read the Csv file.

[CsvMap]
public partial class UserCsvMap : CsvMapBase<User>
{
    //This method is never actually called, but is used to generate the CSV mapping code.
    public void Configure(ICsvMapBuilder<User> builder)
    {
        builder
            .AutoMapByName(StringComparison.OrdinalIgnoreCase);
    }
}

Basic Usage

using var mmf = MemoryMappedFile.CreateFromFile(@"CsvFiles\users-100.csv", FileMode.Open);
using var csvReader = new CsvReader(mmf.CreateViewStream());

var userCsvMap = new UserCsvMap(csvReader);

await UserCsvMap.ReadHeaderRowAsync().ConfigureAwait(false);
var users = await UserCsvMap.ReadDataRowsAsync().ConfigureAwait(false);

About

A very fast CSV parser. Has a ton of features and is easily configurable via a fluent API.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages