Skip to content

russkyc/attachedutilities-filestreamextensions

Repository files navigation

AttachedUtilities.FileStreamExtensions

Nuget

Russkyc.AttachedUtilities.FileStreamExtensions is a collection of filestream attached method utilities for .NET Standard, .NET Core, and .NET Framework.

Setup

//Dependency Import
using Russkyc.AttachedUtilities.FileStreamExtensions;

Filestream Utilities

StreamRead - FileStream Reader.

  • .StreamRead() - Returns string of file content.
  • .StreamReadBytes() - Returns file as byte[] array.
  • .StreamReadLines() - Returns string[] of file content lines.
  • .StreamListLines() - Returns List<string> of file content lines.
  • .StreamReadSplit() - Returns string[] of file contents split by separator.
  • .StreamListSplit() - Returns List<string> array of file contents split by separator.

StreamWrite - FileStream Writer.

  • .StreamCreate() - Creates empty file.
  • .StreamWrite() - Writes text to file. Returns file path.
  • .StreamWriteBytes() - Writes bytes to file. Returns file path.
  • .StreamWriteLines() - Writes text lines to file. Returns file path.
  • .StreamAppend() - Appends text to file. Returns file path.
  • .StreamAppendLines() - Appends text lines to file. Returns file path.

StreamRead Usage:

//File path
string path = @"C:\Testfile.txt";

//Reads file to byte array
byte[] file = path.StreamReadBytes();

//Reads file content
string content = path.StreamRead();

//Reads file content lines to array
string[] lines = path.StreamReadLines();

//Reads delimited file content to array
string[] words = path.StreamReadSplit();

//Reads delimited file content to array
string[] delimited = path.StreamReadSplit(',');

StreamWrite Usage:

//File path
string path = @"C:\Testfile.txt";

//Writes bytes to file
byte[] bytes = {};
path.StreamReadBytes(bytes);

//Creates file
path.StreamCreate();

//Writes text to file
string text = "Hello C#!"
path.StreamWrite(text);

//Appends text to file
string text = "New Text C#!";
path.StreamAppend(text);

//Writes lines to file
string lines = {"Hello Line 1","Hello Line 2","Hello Line 3"};
path.StreamWriteLines(lines);

//Appends lines to file
string lines = {"Hello Line 1","Hello Line 2","Hello Line 3"};
path.StreamAppendLines(lines);