Collection Streamers
Overview
VersaTul.Collection.Streamers turns in-memory collections or forward-only IDataReader sources into reusable export streams such as CSV, tab-delimited text, JSON, and JSONL.
The package is designed for workflows where a collection or row reader needs to be serialized once and then reused for multiple outputs, such as saving to disk, compressing into a zip archive, emailing as attachments, or converting to an IDataReader for downstream processing.
Why Use This Package
Use this package when export generation is becoming a real application concern instead of a one-off helper method.
Its value is that one streamer can drive multiple destinations such as files, compressed archives, and mail attachments while keeping export formatting and serialization logic in one place.
When To Use This Package
Use this package when you want to:
Export collections to CSV, tab-delimited, or JSON files.
Reuse the same serialized output for file, email, and compression workflows.
Convert collections to
IDataReaderform for bulk-processing scenarios.Apply display metadata from Display Attributes during output generation.
Add cancellation-aware stream generation for large exports.
Write very large exports directly to disk without buffering the full file in memory.
Installation
Install the package with the .NET CLI:
dotnet add package VersaTul.Collection.Streamers
Or with the Package Manager Console:
PM> NuGet\Install-Package VersaTul.Collection.Streamers -Version latest
Start Here If
You need CSV, tab-delimited, JSON, or JSONL exports from collections or readers.
The same export output may be saved, compressed, or emailed.
Column naming and formatting matter to the consumer of the export.
Not The Right First Package If
Your workflow is import-first rather than export-first.
You only need a raw SMTP transport or file utility.
You are looking only for metadata annotations without generating output.
Works Well With
Display Attributes when exported names, ordering, and formatting matter.
Object Converters when nested objects need flattening before output.
Compression and Handler File when generated streams must be archived or persisted.
Mailer when exports become outbound attachments.
Data Export Workflow when you want the complete workflow first.
Core Types And Concepts
IStreamerRepresents an export stream with file metadata, headings, an
IDataReader, andGetFileStream()methods.IStreamCreatorDefines the
Create<T>()entry point used to bind a collection to a streamer instance.IDataReaderStreamCreatorAdds a
Create(IDataReader, ...)path for binding existing forward-only row readers.IFileWritableStreamerAdds
WriteToFile()for writing export output directly to disk.CsvStreamer,TabStreamer, andJsonStreamerBuilt-in export implementations for common flat-file formats.
BaseStreamerCommon base class that owns file name handling, collection and reader binding, and cancellation-aware generation.
FileConverterSaves a streamer to disk, optionally as a compressed zip file.
CompressTransportConverts one or many streams into email attachments and compresses them when needed to stay within size limits.
MailTransporterSends stream-based attachments through the mailer stack.
Key Capabilities
Create<T>()binds a collection to a reusable streamer instance.Create(IDataReader, ...)binds an existing reader directly to a streamer.GetFileStream()returns the serialized output as aMemoryStream.GetFileStream(CancellationToken)adds cancellation support during generation.WriteToFile()writes output directly to disk.CollectionReaderExtensions.ToReader()turns collections intoIDataReaderinstances.FileConverter.Save()can persist a streamer as plain output or compressed zip content.
Basic CSV Example
using VersaTul.Collection.Streamers;
using VersaTul.Handler.File;
using VersaTul.Object.Converters;
using VersaTul.Utilities;
var utility = new CommonUtility();
var directoryWrapper = new DirectoryWrapper();
var fileUtility = new FileUtility(directoryWrapper, directoryWrapper);
var flattener = new Flattener();
var csvStreamer = new CsvStreamer(utility, fileUtility, flattener);
using var fileStream = csvStreamer
.Create(people, "people")
.GetFileStream();
IDataReader Example
using VersaTul.Collection.Streamers.Extensions;
using var reader = people.ToReader();
while (reader.Read())
{
Console.WriteLine(reader.GetValue(0));
}
Direct To Disk Example
using VersaTul.Collection.Streamers.Contracts;
var filePath = ((IFileWritableStreamer)csvStreamer.Create(people, "people"))
.WriteToFile("C:\\exports");
IDataReader To Disk Example
using System.Data;
using VersaTul.Collection.Streamers.Contracts;
IDataReader reader = dataService.ExecuteReader(command);
var filePath = ((IFileWritableStreamer)csvStreamer.Create(reader, "orders-export"))
.WriteToFile("C:\\exports");
Save To Disk Example
using VersaTul.Collection.Streamers.Compressions;
using VersaTul.Collection.Streamers.Converters;
using VersaTul.Compression;
var zipper = new Zipper(new Archiver());
var compressor = new Compressor(zipper);
var fileConverter = new FileConverter(fileUtility, compressor);
var streamer = csvStreamer.Create(people, "people");
fileConverter.Save(streamer, "C:\\exports", compressed: true);
Expected Result
When this package is working well:
one export definition can drive multiple delivery paths,
formatting rules stay out of ad hoc file-writing code, and
large exports can be written directly to disk without buffering the full file in memory.
Next Step
Read Data Export Workflow if you want the complete object-to-file workflow.
Read Display Attributes when the next need is column naming, ordering, or value formatting.
Read Mailer if export files now need to be delivered as attachments.
Notes
BaseStreamerreinitializes its internal reader and output stream state each timeCreate(...)is called.CsvStreamersupports a custom encoding strategy for value escaping.WriteToFile()is the preferred path for very large exports because rows can be written directly to disk.FileConverter.Save()uses direct file writing automatically for non-compressed output when the streamer supports it.This package works especially well with Display Attributes when exported column names and formatted values matter.