Skip to content

firenero/AsyncIO

Repository files navigation

AsyncIO

AsyncIO is easy-to-use .NET library for common async IO file system operations. Implemented operations are fully asynchronous and do not use threads from thread pool.

AsyncIO provides decent control over async execution (e.g. support of CancellationToken) and provides API for specifying Encoding.

Installation

You can install AsyncIO from nuget.

Also, you can download compiled dll from the releases page.

Usage

AsyncIO is very easy to use especially if you used System.IO.File. There is a static class AsyncFile to access all supported async io operations. You can also use extension methods for System.IO.FileInfo.

Examples

  • Read text from file
var text = await AsyncFile.ReadAllTextAsync("path_to_file");
  • Read text from file with Encoding
var text = await AsyncFile.ReadAllTextAsync("path_to_file", Encoding.UTF8);
  • CancellationToken usage
var tokenSource = new CancellationTokenSource();
try
{
    var moveTask = AsyncFile.MoveAsync("file_source_path", "file_destination_path", tokenSource.Token);
    tokenSource.Cancel();
    await moveTask;
}
catch (OperationCancelledException e)
{
    // Handle cancellation here.
}
var fileInfo = new FileInfo("path_to_file");
var text = await fileInfo.ReadAllTextAsync("path_to_file");

Supported methods

  • AppendAllLinesAsync
  • AppendAllTextAsync
  • CopyAsync
  • DeleteAsync
  • MoveAsync
  • ReadAllBytesAsync
  • ReadAllLinesAsync
  • ReadAllTextAsync
  • WriteAllBytesAsync
  • WriteAllLinesAsync
  • WriteAllTextAsync

Contribution

Issues tracking

  • Feel free to submit issues with or request new features via GitHub Issues.
  • Before asking questions about library usage, please verify that it isn't covered in Usage section.

Pull requests

  • Before creating new pull request, please create a ticket for it.

Licence

Library is distributing under the MIT license. You can see details here.

Roadmap

  1. Implement async analog of File.Replace method.