using System.IO;
using System.Threading.Tasks;
namespace MarkdownEditor.Services;
///
/// Default implementation of using System.IO.
/// Provides file system operations for reading and writing markdown files.
///
public class FileService : IFileService
{
///
public async Task ReadFileAsync(string path)
{
if (string.IsNullOrWhiteSpace(path))
{
throw new System.ArgumentException("File path cannot be null or empty.", nameof(path));
}
return await File.ReadAllTextAsync(path);
}
///
public async Task WriteFileAsync(string path, string content)
{
if (string.IsNullOrWhiteSpace(path))
{
throw new System.ArgumentException("File path cannot be null or empty.", nameof(path));
}
await File.WriteAllTextAsync(path, content ?? string.Empty);
}
///
public bool FileExists(string path)
{
return !string.IsNullOrWhiteSpace(path) && File.Exists(path);
}
///
public string GetFileName(string path)
{
if (string.IsNullOrWhiteSpace(path))
{
return string.Empty;
}
return Path.GetFileName(path);
}
}