Giter Club home page Giter Club logo

csv's Introduction

NReco.Csv

Ultra-fast C# CSV parser: implements stream reader and writer. NuGet Release

  • very fast: x2-x4 times faster than JoshClose's CSVHelper
  • memory efficient: uses only single circular buffer, no allocations in heap for CSV of any size
  • lightweight: bare csv parser with simple API
  • tolerant to not-fully correct CSV files, you can control max length of CSV file (useful for processing end-user CSV uploads)
  • can be used for stream processing of many-GB CSV files
  • supports all .NET versions: Framework 4.5+, .NET Core, NET6+

How to use

Parse CSV stream:

using (var streamRdr = new StreamReader(inputStream)) {
  var csvReader = new CsvReader(streamRdr, ",");
  while (csvReader.Read()) {
    for (int i=0; i<csvReader.FieldsCount; i++) {
      string val = csvReader[i];
    }
  }
}

Generate CSV to stream:


using (var streamWr = new StreamWriter(outputStream)) {
  var csvWriter = new CsvWriter(streamWr);
  // write line
  csvWriter.WriteField("Value with double quote\"");
  csvWriter.WriteField("And with\nnew line");
  csvWriter.WriteField("Normal");
  csvWriter.NextRecord();
}

Who is using this?

NReco.Csv is in production use at SeekTable.com and PivotData microservice.

License

Copyright 2017-2024 Vitaliy Fedorchenko and contributors

Distributed under the MIT license

csv's People

Contributors

kikaragyozov avatar spiritbob avatar vitaliymf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

csv's Issues

Add IDataReader implementation

In some cases it might be useful to read CSV stream as System.Data IDataReader.
This unlocks simple way to read CSV to DataTable or to list of POCO-models - say, this is possible with DataReaderResult class from NReco.Data library.

In the initial implementation, lets expose all CSV line fields as 'string' FieldType, and add option to skip first (headers) line.

Custom quote

Why there is no possibility to accept a different quote?

Something like this
var csvReader = new CsvReader(stream, delimiter, quote); (eventually also comment char....)

This lib is very fast but also incomplete with only delimiter. I hope you add this feature.

Add API for ReadOnlySpan for efficient values handling

In .NET Core 2.1 and upcoming netstandard 2.1 ReadOnlySpan can be used for zero-allocation handling of string values - without need to create 'string' object from the buffer.

To support this it is enough to add ProcessValueInBuffer overload or maybe add method ReadOnlySpan<char> GetSpanValue(int idx).

Encoding issue in readme

Example in Readme has &lt; instead of <

for (int i=0; i&lt;csvReader.FieldsCount; i++) {
for (int i=0; i<csvReader.FieldsCount; i++) {

Feature for getting count of read and skipped lines.

Introduce 2 new properties - SkippedLines and ReadLines or similarly named that gets the point across.

  • SkippedLines - returns the number of skipped lines of the file.
  • ReadLines - returns the number of read lines of the file.

I'll attempt to tackle this now as I'm in need of it. Let me know if this is something you'd like to see implemented in the library!

JSON field support

File contains 3 columns:
AddressId, JsonData, UpdatedAt
1,"{"address": {"zip": null, "city": null, "state": null, "country": "USA", "street1": null, "street2": null, "street3": null}}","2021-03-31T23:36:04"
2,"{"guardian": {"name": "Abhishek", "phone": true, "address": {"zip": "6204", "city": "York", "state": "PA", "country": "USA", "street1": "62115B Greenwood Rd", "street2": null, "street3": null}, "relationship": "Son"}}","2021-03-31T23:36:04"

image

I am not able to find "UpdatedAt" field at csvReader[2]. Please add json support also. thanks

[Question] Does NReco.Csv write fully-correct CSV files?

It seems the library is capable of reading not fully correct CSV files. if you can expand on the differences, as I'm guessing your model is specified in RFC4180?

With that said, does the library itself produce CSV files conforming to the above RFC standard?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.