Skip to content

Using the AsyncFileReaders

Paul Joiner edited this page Nov 2, 2019 · 5 revisions

Beginning with version 0.3.0 of the library files may be read asynchronously using the IAsyncFileReader interface.

Note: Version 0.3.0 requires dotnet standard 2.1 or dotnet Core 3.0.

Contents

Reading Core File Data

    using DwC_A;
    using DwC_A.Terms;
    using System.Linq;

    class Program
    {
        static async Task Main()
        {

            string fileName = "./dwca-uta_herps-v8.1.zip";
            using (var archive = new ArchiveReader(fileName))
            {
                await foreach(var row in archive.GetAsyncCoreFile().GetDataRowsAsync())
                {
                    //Access fields by index
                    Console.WriteLine(row[0]);
                    //Access fields by Term
                    Console.WriteLine(row[Terms.type]);
                    //Iterate over or query fields in a row using LinQ
                    var fields = row.Fields.ToList().Aggregate((current, next) => $"{current}\t{next}");
                    Console.WriteLine(fields);
                }
            }
        }
    }

Reading Extension Files

Extension files may be accessed using the new GetAsyncFileReaderByFileName or GetAsyncFileReadersByRowType methods of the FileReaderCollection class.

var fileName = "occurrence.txt";
IAsyncFileReader fileReader = archive.Extensions.GetAsyncFileReaderByFileName(fileName);
IEnumerable<IAsyncFileReader> fileReaders = archive.Extensions.GetAsyncFileReadersByRowType(RowTypes.Occurrence); 
Clone this wiki locally