All Projects → airbreather → Cursively

airbreather / Cursively

Licence: MIT license
A CSV reader for .NET. Fast, RFC 4180 compliant, and fault tolerant. UTF-8 only.

Programming Languages

C#
18002 projects
Batchfile
5799 projects

Projects that are alternatives of or similar to Cursively

CsvTextFieldParser
A simple CSV parser based on Microsoft.VisualBasic.FileIO.TextFieldParser.
Stars: ✭ 40 (+17.65%)
Mutual labels:  csv-reading, csv-parser, csv-reader, csv-parsing
comma splice
Fixes CSVs with unquoted commas in values
Stars: ✭ 67 (+97.06%)
Mutual labels:  csv-files, csv-reading, csv-parser
java-read-write-csv-file
Read and Write CSV files in Java using Apache Commons CSV and OpenCSV
Stars: ✭ 57 (+67.65%)
Mutual labels:  csv-parser, csv-reader
VBA-CSV-interface
The most powerful and comprehensive CSV/TSV/DSV data management library for VBA, providing parsing/writing capabilities compliant with RFC-4180 specifications and a complete set of tools for manipulating records and fields.
Stars: ✭ 24 (-29.41%)
Mutual labels:  csv-parser, csv-reader
gpx-converter
python package for manipulating gpx files and easily converting gpx to other different formats
Stars: ✭ 54 (+58.82%)
Mutual labels:  csv-files, csv-parser
Adaptivetablelayout
Library that makes it possible to read, edit and write CSV files
Stars: ✭ 1,871 (+5402.94%)
Mutual labels:  csv-files, csv-reader
csvlixir
A CSV reading/writing application for Elixir.
Stars: ✭ 32 (-5.88%)
Mutual labels:  csv-reading, csv-parser
lazycsv
A fast, lightweight and single-header c++ csv parser library
Stars: ✭ 53 (+55.88%)
Mutual labels:  csv-parser, csv-reader
Awesomecsv
🕶️A curated list of awesome tools for dealing with CSV.
Stars: ✭ 305 (+797.06%)
Mutual labels:  csv-files, csv-parser
Filehelpers
The FileHelpers are a free and easy to use .NET library to read/write data from fixed length or delimited records in files, strings or streams
Stars: ✭ 917 (+2597.06%)
Mutual labels:  csv-files, csv-parser
Clevercsv
CleverCSV is a Python package for handling messy CSV files. It provides a drop-in replacement for the builtin CSV module with improved dialect detection, and comes with a handy command line application for working with CSV files.
Stars: ✭ 887 (+2508.82%)
Mutual labels:  csv-files, csv-parser
Intellij Csv Validator
CSV validator, highlighter and formatter plugin for JetBrains Intellij IDEA, PyCharm, WebStorm, ...
Stars: ✭ 198 (+482.35%)
Mutual labels:  csv-files, csv-parser
Csv File Validator
🔧🔦 Validation of CSV file against user defined schema (returns back object with data and invalid messages)
Stars: ✭ 60 (+76.47%)
Mutual labels:  csv-files, csv-parser
Windmill
A library to parse or write Excel and CSV files through a fluent API
Stars: ✭ 19 (-44.12%)
Mutual labels:  csv-parser, csv-reader
csv-localizer
Command Line Interface that convert CSV file to iOS, Android or JSON localizable strings
Stars: ✭ 84 (+147.06%)
Mutual labels:  csv-parser
Winmerge
WinMerge is an Open Source differencing and merging tool for Windows. WinMerge can compare both folders and files, presenting differences in a visual text format that is easy to understand and handle.
Stars: ✭ 2,358 (+6835.29%)
Mutual labels:  csv-files
Csvimporter
Import CSV files line by line with ease
Stars: ✭ 120 (+252.94%)
Mutual labels:  csv-files
XamarinFormsPinView
PIN keyboard for Xamarin.Forms.
Stars: ✭ 83 (+144.12%)
Mutual labels:  netstandard20
po-csv
Convert gettext PO files from CSV files and merge them back in.
Stars: ✭ 32 (-5.88%)
Mutual labels:  csv-files
Csv2db
The CSV to database command line loader
Stars: ✭ 102 (+200%)
Mutual labels:  csv-files

Cursively

A fast, RFC 4180-conforming CSV reading library for .NET. Written in C#.

License CI (AppVeyor) NuGet MyGet (pre-release)
License CI NuGet MyGet

Documentation

Documentation is currently being published as GitHub Pages.

Usage

Create a subclass of CsvReaderVisitorBase (or one of its own built-in subclasses) with your own logic for processing the individual elements in order. Then, you have some options.

Example Visitor

public sealed class MyVisitor : CsvReaderVisitorBase
{
    private readonly Decoder _utf8Decoder = Encoding.UTF8.GetDecoder();

    private readonly char[] _buffer;

    private int _bufferConsumed;

    public MyVisitor(int maxFieldLength) =>
        _buffer = new char[maxFieldLength];

    public override void VisitPartialFieldContents(ReadOnlySpan<byte> chunk) =>
        VisitFieldContents(chunk, flush: false);

    public override void VisitEndOfField(ReadOnlySpan<byte> chunk) =>
        VisitFieldContents(chunk, flush: true);

    public override void VisitEndOfRecord() =>
        Console.WriteLine("End of fields for this record.");

    private void VisitFieldContents(ReadOnlySpan<byte> chunk, bool flush)
    {
        int charCount = _utf8Decoder.GetCharCount(chunk, flush);
        if (charCount + _bufferConsumed <= _buffer.Length)
        {
            _utf8Decoder.GetChars(chunk, new Span<char>(_buffer, _bufferConsumed, charCount), flush);
            _bufferConsumed += charCount;
        }
        else
        {
            throw new InvalidDataException($"Field is longer than {_buffer.Length} characters.");
        }

        if (flush)
        {
            Console.Write("Field: ");
            Console.WriteLine(_buffer, 0, _bufferConsumed);
            _bufferConsumed = 0;
        }
    }
}

Fastest

All of the other methods of processing the data are built on top of this, so it gives you the most control:

  1. Create a new instance of your visitor.
  2. Create a new instance of CsvTokenizer.
  3. Call CsvTokenizer.ProcessNextChunk for each chunk of the file.
  4. Call CsvTokenizer.ProcessEndOfStream after the last chunk of the file.

Example:

public static void ProcessCsvFile(string csvFilePath)
{
    var myVisitor = new MyVisitor(maxFieldLength: 1000);
    var tokenizer = new CsvTokenizer();
    using (var file = File.OpenRead(csvFilePath))
    {
        Console.WriteLine($"Started reading '{csvFilePath}'.");
        Span<byte> fileReadBuffer = new byte[4096];
        while (true)
        {
            int count = file.Read(fileReadBuffer);
            if (count == 0)
            {
                break;
            }

            var chunk = fileReadBuffer.Slice(0, count);
            tokenizer.ProcessNextChunk(chunk, myVisitor);
        }

        tokenizer.ProcessEndOfStream(myVisitor);
    }

    Console.WriteLine($"Finished reading '{csvFilePath}'.");
}

Simpler

  1. Create a new instance of your visitor.
  2. Use one of the CsvSyncInput or CsvAsyncInput methods to create an input object you can use to describe the data to your visitor.

Examples:

public static void ProcessCsvFile(string csvFilePath)
{
    Console.WriteLine($"Started reading '{csvFilePath}'.");
    CsvSyncInput.ForMemoryMappedFile(csvFilePath)
                .Process(new MyVisitor(maxFieldLength: 1000));
    Console.WriteLine($"Finished reading '{csvFilePath}'.");
}

public static void ProcessCsvStream(Stream csvStream)
{
    Console.WriteLine($"Started reading CSV file.");
    CsvSyncInput.ForStream(csvStream)
                .Process(new MyVisitor(maxFieldLength: 1000));
    Console.WriteLine($"Finished reading CSV file.");
}

public static async Task ProcessCsvStreamAsync(Stream csvStream)
{
    Console.WriteLine($"Started reading CSV file.");
    await CsvAsyncInput.ForStream(csvStream)
                       .ProcessAsync(new MyVisitor(maxFieldLength: 1000));
    Console.WriteLine($"Finished reading CSV file.");
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].