-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileText.cs
33 lines (27 loc) · 833 Bytes
/
FileText.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using TextAnalyzer.Infrastructure.Interfaces;
namespace TextAnalyzer.DataProvider.Model;
public class FileText : IText
{
protected readonly string path;
protected FileText(string path)
{
this.path = path;
Title = Path.GetFileName(path);
Format = Path.GetExtension(path);
Group = new FileInfo(path).Directory!.Name;
}
public string Format { get; init; }
public string Title { get; set; }
public string Group { get; init; }
public virtual async IAsyncEnumerable<string> ReadAsync()
{
await using var stream = ReadFile();
using var reader = new StreamReader(stream);
var result = await reader.ReadToEndAsync();
yield return result;
}
protected virtual Stream ReadFile()
{
return File.OpenRead(path);
}
}