Data FileReader
Overview
VersaTul.Data.FileReader provides simple, testable file-reading helpers that produce IDataReader instances from common file formats.
It is especially useful when your downstream workflow already expects IDataReader input, such as a bulk-copy pipeline or a tabular import process.
Why Use This Package
Use this package when the hard part of the problem is turning flat files into a tabular shape the rest of your pipeline can consume.
Its main value is that it bridges file input into IDataReader-based workflows without forcing you to hand-roll parsing glue for every import job.
When To Use This Package
Use this package when you want to:
Read CSV, text, or JSON files through a consistent abstraction.
Enumerate files in a directory by extension and turn each into an
IDataReader.Inject format-specific readers for testing or replacement.
Feed file data directly into Data Bulk or Data MsSql bulk-copy workflows.
Installation
Install the package with the .NET CLI:
dotnet add package VersaTul.Data.FileReader
Or with the Package Manager Console:
PM> NuGet\Install-Package VersaTul.Data.FileReader -Version latest
Start Here If
Your source data is in CSV, text, or JSON files.
The next processing step expects
IDataReaderinput.You want the import path to remain testable and replaceable.
Not The Right First Package If
Your real need is export generation rather than import parsing.
You need direct SQL Server bulk upload but do not yet have file input in a readable shape.
You only need raw file-system utilities instead of tabular readers.
Works Well With
Data Bulk when the next step is schema mapping and transport-neutral bulk copy.
Data MsSql when the destination is SQL Server bulk upload.
Handler File when files must be discovered, moved, or archived around the import process.
File Import Workflow when you want the full workflow before going deeper into the reference page.
Core Types And Concepts
IFileReaderandDataFileReaderThe main API for reading a single file or a directory of files into
IDataReaderinstances.ICsvReaderandCsvFileReaderCSV-specific reader abstraction and implementation.
ITextReaderandTextFileReaderPlain-text reader abstraction and implementation.
IOptionsandFileOptionsFile-reader options for header handling, extension filters, and directory search behavior.
ExtensionFiltersEnum that describes the supported file types.
DisposableDataReaderWrapper that ensures the returned reader and its underlying stream are disposed together.
Key Capabilities
Read one file by directory and file name.
Read all matching files in a directory based on
ExtensionFilters.Control whether the file contains a header row.
Control directory search behavior with
SearchOption.Swap reader implementations for tests or alternate parsing behavior.
Basic Example
using VersaTul.Data.FileReader;
var fileReader = new DataFileReader(fileUtility, csvReader, textReader);
var options = new FileOptions { HasHeader = true };
using var reader = fileReader.Read("C:\\path\\to", "file.csv", options);
if (reader != null)
{
while (reader.Read())
{
// Consume row data here.
}
}
Directory Example
var options = new FileOptions
{
HasHeader = true,
ExtensionFilters = new[] { ExtensionFilters.CSV, ExtensionFilters.TEXT },
SearchOption = SearchOption.AllDirectories
};
var readers = fileReader.Read("C:\\data", options);
foreach (var item in readers)
{
using (item)
{
while (item.Read())
{
}
}
}
Bulk Workflow Example
var options = new FileOptions { HasHeader = true };
using var reader = fileReader.Read("C:\\data", "people.csv", options);
var mappings = new List<IBulkCopyColumnMapping>
{
new BulkCopyColumnMapping<Person, Person>(p => p.Name, p => p.Name),
new BulkCopyColumnMapping<Person, Person>(p => p.Age, p => p.Age)
};
var copyDetail = new CopyDetail("Persons", reader, mappings);
await bulkCopy.DoCopyAsync(copyDetail);
Expected Result
When this package is working well:
import code stays focused on workflow instead of parsing details,
files become
IDataReadersources that other VersaTul packages can consume directly, andone-file and many-file imports follow the same mental model.
Next Step
Read File Import Workflow if you want to connect the reader to a complete database import path.
Read Data Bulk if the next question is column mapping and copy results.
Read Data MsSql if SQL Server bulk upload is the real destination.
Dependency Injection
Typical registrations look like this:
builder.RegisterType<FileUtility>().As<IFileUtility>().SingleInstance();
builder.RegisterType<CsvFileReader>().As<ICsvReader>().SingleInstance();
builder.RegisterType<TextFileReader>().As<ITextReader>().SingleInstance();
builder.RegisterType<DataFileReader>().As<IFileReader>().SingleInstance();
Notes
DataFileReaderdelegates parsing to the registered reader implementations.FileOptionsdefaults to common text, CSV, and JSON extension filters.This package is most valuable when your next processing step wants an
IDataReaderinstead of raw file lines.