VersaTul.Collection.Streamers
1.0.34
Prefix Reserved
dotnet add package VersaTul.Collection.Streamers --version 1.0.34
NuGet\Install-Package VersaTul.Collection.Streamers -Version 1.0.34
<PackageReference Include="VersaTul.Collection.Streamers" Version="1.0.34" />
<PackageVersion Include="VersaTul.Collection.Streamers" Version="1.0.34" />
<PackageReference Include="VersaTul.Collection.Streamers" />
paket add VersaTul.Collection.Streamers --version 1.0.34
#r "nuget: VersaTul.Collection.Streamers, 1.0.34"
#:package VersaTul.Collection.Streamers@1.0.34
#addin nuget:?package=VersaTul.Collection.Streamers&version=1.0.34
#tool nuget:?package=VersaTul.Collection.Streamers&version=1.0.34
VersaTul Collection Streamers
VersaTul Collection Streamers is a library for turning collections or forward-only IDataReader sources into reusable export streams such as CSV, tab-delimited text, JSON, and JSONL. It also works with display attributes to manipulate the properties on the objects in the collection.
Features
- Convert from a data-reader to other file formats such as CSV, TAB or JSON
- Stream large exports directly to disk without first buffering the full file in memory
- Use display attributes to format or rename the properties
- Send streamers via email attachments
- Save streamers to physical files on disk
- Compress streamers for transport over the network
- Convert any collection to an IDataReader
Installation
To use VersaTul Collection Streamers, first install it using nuget:
PM> NuGet\Install-Package VersaTul.Collection.Streamers -Version latest
Usage
The library provides several interfaces and classes to create and manipulate streamers. Here are some of the main ones:
IStreamer: A base interface that represents the data contained in the stream and the functionality that can be applied to the data.IStreamCreator: A base interface that represents the functionality for creating streamers.IDataReaderStreamCreator: Adds support for binding an existingIDataReaderto a streamer.IFileWritableStreamer: Adds direct-to-disk writing throughWriteToFile(...).ICsvStreamer: A specific stream type interface that represents the functionality for creating csv streamers.ITabStreamer: A specific stream type interface that represents the functionality for creating tab streamers.IJsonStreamer: A specific stream type interface that represents the functionality for creating json streamers.BaseStreamer: A concrete implementation of the core streamer contracts, providing common functionality for collection-backed andIDataReader-backed exports.CsvStreamer: A concrete implementation of theICsvStreamerinterface.JsonStreamer: A concrete implementation of theIJsonStreamerinterface.TabStreamer: A concrete implementation of theITabStreamerinterface.IMailTransporter: Represents a set of functionality to send streamers via email attachments.IStreamFileConverter: Represent a set of conversion techniques that can be applied to a streamer. For plain file output, this now prefersWriteToFile(...)when the streamer supports it.ICompressTransport: Represents a set of functionality to reduce streamers for transport over the network.CollectionReaderExtensions: Contains theToReadermethod that can be used to convert any collection to anIDataReader.
Example: Collection To CSV File
using VersaTul.Collection.Streamers;
using VersaTul.Handler.File;
using VersaTul.Object.Converters;
using VersaTul.Utilities;
namespace CollectionStreamers
{
class Program
{
static void Main(string[] args)
{
var people = GetPeople(1000);
var directoryWrapper = new DirectoryWrapper();
var utility = new CommonUtility();
var flattener = new Flattener();
var fileUtil = new FileUtility(directoryWrapper, directoryWrapper);
var csvStreamer = new CsvStreamer(utility, fileUtil, flattener);
var filePath = ((IFileWritableStreamer)csvStreamer.Create(people, "people"))
.WriteToFile("C:\\your\\file\\path\\here\\");
Console.WriteLine(filePath);
}
private static IEnumerable<Person> GetPeople(int amount)
{
var people = new List<Person>(amount);
var names = new[] { "John Doe", "Jane Smith", "Susan Williams", "Mike Burger", "Joe Williams", "Timmy Smith", "Lisa Ray", "Stanley Smith", "Sam Jones", };
for (int i = 0; i < amount; i++)
{
people.Add(new Person
{
Age = i + 10,
Name = CommonUtil.RandomSampler(names),
AccountBalance = (100.99m * i),
BestFriend = CommonUtil.RandomSampler(people)
});
}
return people;
}
}
// Data Model
public class Person
{
public int Age { get; set; }
public string? Name { get; set; }
public decimal AccountBalance { get; set; }
public IEnumerable<Person>? Friends { get; set; }
public Person? BestFriend { get; set; }
}
// Helper class
public static class CommonUtil
{
public static T? RandomSampler<T>(IList<T> source)
{
var max = source.Count;
if (max == 0) return default;
var rand = new Random();
var position = rand.Next(max);
return source[position];
}
}
}
Example: Stream SQL Reader Rows Directly To Disk
using System.Data;
using VersaTul.Collection.Streamers;
using VersaTul.Collection.Streamers.Contracts;
using VersaTul.Handler.File;
using VersaTul.Object.Converters;
using VersaTul.Utilities;
IDataReader reader = dataService.ExecuteReader(command);
var directoryWrapper = new DirectoryWrapper();
var utility = new CommonUtility();
var flattener = new Flattener();
var fileUtil = new FileUtility(directoryWrapper, directoryWrapper);
var csvStreamer = new CsvStreamer(utility, fileUtil, flattener);
var filePath = ((IFileWritableStreamer)csvStreamer.Create(reader, "orders-export"))
.WriteToFile("C:\\exports");
Example: Keep Using In-Memory Streams
var csvStreamer = new CsvStreamer(utility, fileUtil, flattener);
using var fileStream = csvStreamer
.Create(people, "people")
.GetFileStream();
Notes
Create(IDataReader, ...)lets you bind a forward-only reader without first materializing a collection.WriteToFile(...)is the preferred path for very large exports because rows can be written directly to disk.GetFileStream()remains available for callers that still need an in-memoryMemoryStream.FileConverter.Save()now uses the direct file-writing path automatically for non-compressed output when the streamer supports it.
License
This project is licensed under the MIT License - see the LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Newtonsoft.Json (>= 13.0.3)
- VersaTul.Compression (>= 1.0.17)
- VersaTul.Extensions (>= 1.0.16)
- VersaTul.Handler.File (>= 1.0.20)
- VersaTul.Mailer (>= 1.0.17)
- VersaTul.Object.Converters (>= 1.0.15)
- VersaTul.Utilities (>= 1.0.16)
-
net9.0
- Newtonsoft.Json (>= 13.0.3)
- VersaTul.Compression (>= 1.0.17)
- VersaTul.Extensions (>= 1.0.16)
- VersaTul.Handler.File (>= 1.0.20)
- VersaTul.Mailer (>= 1.0.17)
- VersaTul.Object.Converters (>= 1.0.15)
- VersaTul.Utilities (>= 1.0.16)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.34 | 37 | 5/23/2026 |
| 1.0.33 | 128 | 3/22/2026 |
| 1.0.32 | 110 | 3/20/2026 |
| 1.0.31 | 289 | 12/10/2024 |
| 1.0.30 | 232 | 10/12/2024 |
| 1.0.29 | 258 | 5/30/2024 |
| 1.0.28 | 254 | 4/5/2024 |
| 1.0.27 | 253 | 4/4/2024 |
| 1.0.26 | 238 | 4/4/2024 |
| 1.0.25 | 263 | 3/1/2024 |
| 1.0.24 | 243 | 2/2/2024 |
| 1.0.23 | 252 | 1/28/2024 |
| 1.0.22 | 241 | 1/25/2024 |
| 1.0.21 | 242 | 1/23/2024 |
| 1.0.20 | 235 | 1/23/2024 |
| 1.0.19 | 228 | 1/15/2024 |
| 1.0.18 | 241 | 1/11/2024 |
| 1.0.17 | 234 | 1/11/2024 |
| 1.0.16 | 241 | 1/11/2024 |
| 1.0.15 | 264 | 12/16/2023 |