11using System ;
22using System . IO ;
3+ using System . Threading ;
4+ using System . Threading . Tasks ;
35
46
57namespace WriterSharp . PluginApi . FileSystem
@@ -12,28 +14,26 @@ namespace WriterSharp.PluginApi.FileSystem
1214 public interface IFileSystem
1315 {
1416
15- #region Reading
16-
1717 /// <summary>
1818 /// Reads all text from a file.
1919 /// </summary>
2020 /// <param name="filepath">The path to the file</param>
2121 /// <returns>The contents of the file</returns>
22- public string ReadAllText ( string filepath ) ;
22+ public Task < string > ReadAllTextAsync ( string filepath , CancellationToken cancellationToken = default ) ;
2323
2424 /// <summary>
2525 /// Reads all text from a file, as a list of lines.
2626 /// </summary>
2727 /// <param name="filepath">The path to the file</param>
2828 /// <returns>The contents of the file</returns>
29- public string [ ] ReadAllLines ( string filepath ) ;
29+ public Task < string [ ] > ReadAllLinesAsync ( string filepath , CancellationToken cancellationToken = default ) ;
3030
3131 /// <summary>
3232 /// Reads the very first line of a file.
3333 /// </summary>
3434 /// <param name="filepath">The path to the file</param>
3535 /// <returns>The first line of the file</returns>
36- public string ReadLine ( string filepath ) ;
36+ public Task < string > ReadLineAsync ( string filepath , CancellationToken cancellationToken = default ) ;
3737
3838 /// <summary>
3939 /// Reads a specific amount of characters from a file buffer.
@@ -42,49 +42,37 @@ public interface IFileSystem
4242 /// <param name="amount">The amount of characters to read</param>
4343 /// <param name="offset">The index from which to start reading the characters</param>
4444 /// <returns>A span of characters</returns>
45- public Span < char > ReadCharacters ( string filepath , ulong amount , long offset = 0 ) ;
46-
47- #endregion
48-
49- #region Writing
45+ public Task < nint > ReadCharactersAsync ( string filepath , ulong amount , long offset = 0 , CancellationToken cancellationToken = default ) ;
5046
5147 /// <summary>
5248 /// Writes text to a file, creating it if necessary. If the file exists,
5349 /// it will be overwritten.
5450 /// </summary>
5551 /// <param name="filepath">The path to the file</param>
5652 /// <param name="data">The text to write</param>
57- public void WriteAllText ( string filepath , string data ) ;
53+ public Task WriteAllTextAsync ( string filepath , string data , CancellationToken cancellationToken = default ) ;
5854
5955 /// <summary>
6056 /// Writes lines of text to a file, creating it if necessary.
6157 /// If the file exists, it will be overwritten.
6258 /// </summary>
6359 /// <param name="filepath">The path to the file</param>
6460 /// <param name="data">The lines of text to write</param>
65- public void WriteAllLines ( string filepath , string [ ] data ) ;
66-
67- #endregion
68-
69- #region Appending
61+ public Task WriteAllLinesAsync ( string filepath , string [ ] data , CancellationToken cancellationToken = default ) ;
7062
7163 /// <summary>
7264 /// Appends all the text to the end of a file.
7365 /// </summary>
7466 /// <param name="filepath">The path to the file</param>
7567 /// <param name="data">The text to append</param>
76- public void AppendAllText ( string filepath , string data ) ;
68+ public Task AppendAllTextAsync ( string filepath , string data , CancellationToken cancellationToken = default ) ;
7769
7870 /// <summary>
7971 /// Appends all the specified lines of text to the end of a file.
8072 /// </summary>
8173 /// <param name="filepath">The path to the file</param>
8274 /// <param name="data">The lines to append</param>
83- public void AppendAllLines ( string filepath , string [ ] data ) ;
84-
85- #endregion
86-
87- #region Sharding Toolkit
75+ public Task AppendAllLinesAsync ( string filepath , string [ ] data , CancellationToken cancellationToken = default ) ;
8876
8977 /// <summary>
9078 /// Checks if a file is in use by another plugin.
@@ -95,21 +83,17 @@ public interface IFileSystem
9583 /// <returns><c>true</c> if in use by another plugin</returns>
9684 public bool InUse ( string filepath ) ;
9785
98- #endregion
99-
100- #region Locking
101-
10286 /// <summary>
10387 /// Locks a file, to prevent it from being accessed by other plugins.
10488 /// </summary>
10589 /// <param name="filepath">The path to the file to lock</param>
106- public void Lock ( string filepath ) ;
90+ public Task LockAsync ( string filepath , CancellationToken cancellationToken = default ) ;
10791
10892 /// <summary>
10993 /// Unlocks a previously locked file.
11094 /// </summary>
11195 /// <param name="filepath">The path to the file</param>
112- public void Unlock ( string filepath ) ;
96+ public Task UnlockAsync ( string filepath , CancellationToken cancellationToken = default ) ;
11397
11498 /// <summary>
11599 /// Checks if a file is locked.
@@ -134,23 +118,23 @@ public interface IFileSystem
134118 /// <returns><c>true</c> if it can be locked</returns>
135119 public bool IsLockable ( string filepath ) ;
136120
137- #endregion
138-
139- #region Stream
140-
141- /// <inheritdoc cref="File.OpenRead(String)" />
142- public FileStream OpenRead ( string filepath ) ;
143-
144- /// <inheritdoc cref="File.OpenWrite(String)" />
145- public FileStream OpenWrite ( string filepath ) ;
121+ /// <inheritdoc cref="System.IO.File.OpenRead(String)" />
122+ public Task < FileStream > OpenReadAsync ( string filepath , CancellationToken cancellationToken = default ) ;
146123
147- /// <inheritdoc cref="File.OpenText (String)" />
148- public FileStream OpenText ( string filepath ) ;
124+ /// <inheritdoc cref="System.IO. File.OpenWrite (String)" />
125+ public Task < FileStream > OpenWriteAsync ( string filepath , CancellationToken cancellationToken = default ) ;
149126
150- /// <inheritdoc cref="File.Open (String, FileMode, FileAccess, FileShare )" />
151- public FileStream Open ( string filepath , FileMode mode , FileAccess access , FileShare share ) ;
127+ /// <inheritdoc cref="System.IO. File.OpenText (String)" />
128+ public Task < FileStream > OpenTextAsync ( string filepath , CancellationToken cancellationToken = default ) ;
152129
153- #endregion
130+ /// <inheritdoc cref="System.IO.File.Open(String, FileMode, FileAccess, FileShare)" />
131+ public Task < FileStream > OpenAsync (
132+ string filepath ,
133+ FileMode mode ,
134+ FileAccess access ,
135+ FileShare share ,
136+ CancellationToken cancellationToken = default
137+ ) ;
154138
155139 }
156140
0 commit comments