aboutsummaryrefslogtreecommitdiff
path: root/lib/VNLib.Plugins.Extensions.Data/src/Storage/ISimpleFilesystem.cs
blob: d3dc431961b1e943bac3799c61cbb1d85feb3d79 (plain)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* Copyright (c) 2023 Vaughn Nugent
* 
* Library: VNLib
* Package: VNLib.Plugins.Extensions.Data
* File: ISimpleFilesystem.cs 
*
* ISimpleFilesystem.cs is part of VNLib.Plugins.Extensions.Data which is part 
* of the larger VNLib collection of libraries and utilities.
*
* VNLib.Plugins.Extensions.Data is free software: you can redistribute it and/or modify 
* it under the terms of the GNU Affero General Public License as 
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* VNLib.Plugins.Extensions.Data is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program.  If not, see https://www.gnu.org/licenses/.
*/

using System.IO;
using System.Threading;
using System.Threading.Tasks;

namespace VNLib.Plugins.Extensions.Data.Storage
{

    /// <summary>
    /// Represents an opaque storage interface that abstracts simple storage operations
    /// ignorant of the underlying storage system.
    /// </summary>
    public interface ISimpleFilesystem
    {
        /// <summary>
        /// Gets the full public file path for the given relative file path
        /// </summary>
        /// <param name="filePath">The relative file path of the item to get the full path for</param>
        /// <returns>The full relative file path</returns>
        string GetExternalFilePath(string filePath);

        /// <summary>
        /// Deletes a file from the storage system asynchronously
        /// </summary>
        /// <param name="filePath">The path to the file to delete</param>
        /// <param name="cancellation">A token to cancel the operation</param>
        /// <returns>A task that represents and asynchronous work</returns>
        Task DeleteFileAsync(string filePath, CancellationToken cancellation);

        /// <summary>
        /// Writes a file from the stream to the given file location
        /// </summary>
        /// <param name="filePath">The path to the file to write to</param>
        /// <param name="data">The file data to stream</param>
        /// <param name="contentType">The content type of the file to write</param>
        /// <param name="cancellation">A token to cancel the operation</param>
        /// <returns>A task that represents and asynchronous work</returns>
        Task SetFileAsync(string filePath, Stream data, string contentType, CancellationToken cancellation);

        /// <summary>
        /// Reads a file from the storage system at the given path asynchronously
        /// </summary>
        /// <param name="filePath">The file to read</param>
        /// <param name="output">The stream to write the file output to</param>
        /// <param name="cancellation">A token to cancel the operation</param>
        /// <returns>The number of bytes read, -1 if the operation failed</returns>
        Task<long> ReadFileAsync(string filePath, Stream output, CancellationToken cancellation);
    }
}