From bf01b244f3bf2aa3c236fb86c0d75c261f54b334 Mon Sep 17 00:00:00 2001 From: vnugent Date: Tue, 29 Aug 2023 11:18:36 -0400 Subject: integrate simple fs in utils --- .../src/Storage/FsExtensions.cs | 72 ---------------------- .../src/Storage/ISimpleFilesystem.cs | 72 ---------------------- 2 files changed, 144 deletions(-) delete mode 100644 lib/VNLib.Plugins.Extensions.Data/src/Storage/FsExtensions.cs delete mode 100644 lib/VNLib.Plugins.Extensions.Data/src/Storage/ISimpleFilesystem.cs (limited to 'lib/VNLib.Plugins.Extensions.Data/src') diff --git a/lib/VNLib.Plugins.Extensions.Data/src/Storage/FsExtensions.cs b/lib/VNLib.Plugins.Extensions.Data/src/Storage/FsExtensions.cs deleted file mode 100644 index 8f5c099..0000000 --- a/lib/VNLib.Plugins.Extensions.Data/src/Storage/FsExtensions.cs +++ /dev/null @@ -1,72 +0,0 @@ -/* -* Copyright (c) 2023 Vaughn Nugent -* -* Library: VNLib -* Package: VNLib.Plugins.Extensions.Data -* File: FsExtensions.cs -* -* FsExtensions.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 -{ - /// - /// Contains filesystem extension methods - /// - public static class FsExtensions - { - /// - /// Creates a new scope for the given filesystem. All operations will be offset by the given path - /// within the parent filesystem. - /// - /// - /// The base path to prepend to all requests - /// A new with a new filesystem directory scope - public static ISimpleFilesystem CreateNewScope(this ISimpleFilesystem fs, string offsetPath) => new FsScope(fs, offsetPath); - - private sealed record class FsScope(ISimpleFilesystem Parent, string OffsetPath) : ISimpleFilesystem - { - public Task DeleteFileAsync(string filePath, CancellationToken cancellation) - { - string path = Path.Combine(OffsetPath, filePath); - return Parent.DeleteFileAsync(path, cancellation); - } - - public string GetExternalFilePath(string filePath) - { - string path = Path.Combine(OffsetPath, filePath); - return Parent.GetExternalFilePath(path); - } - - public Task ReadFileAsync(string filePath, Stream output, CancellationToken cancellation) - { - string path = Path.Combine(OffsetPath, filePath); - return Parent.ReadFileAsync(path, output, cancellation); - } - - public Task SetFileAsync(string filePath, Stream data, string contentType, CancellationToken cancellation) - { - string path = Path.Combine(OffsetPath, filePath); - return Parent.SetFileAsync(path, data, contentType, cancellation); - } - } - } -} diff --git a/lib/VNLib.Plugins.Extensions.Data/src/Storage/ISimpleFilesystem.cs b/lib/VNLib.Plugins.Extensions.Data/src/Storage/ISimpleFilesystem.cs deleted file mode 100644 index d3dc431..0000000 --- a/lib/VNLib.Plugins.Extensions.Data/src/Storage/ISimpleFilesystem.cs +++ /dev/null @@ -1,72 +0,0 @@ -/* -* 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 -{ - - /// - /// Represents an opaque storage interface that abstracts simple storage operations - /// ignorant of the underlying storage system. - /// - public interface ISimpleFilesystem - { - /// - /// Gets the full public file path for the given relative file path - /// - /// The relative file path of the item to get the full path for - /// The full relative file path - string GetExternalFilePath(string filePath); - - /// - /// Deletes a file from the storage system asynchronously - /// - /// The path to the file to delete - /// A token to cancel the operation - /// A task that represents and asynchronous work - Task DeleteFileAsync(string filePath, CancellationToken cancellation); - - /// - /// Writes a file from the stream to the given file location - /// - /// The path to the file to write to - /// The file data to stream - /// The content type of the file to write - /// A token to cancel the operation - /// A task that represents and asynchronous work - Task SetFileAsync(string filePath, Stream data, string contentType, CancellationToken cancellation); - - /// - /// Reads a file from the storage system at the given path asynchronously - /// - /// The file to read - /// The stream to write the file output to - /// A token to cancel the operation - /// The number of bytes read, -1 if the operation failed - Task ReadFileAsync(string filePath, Stream output, CancellationToken cancellation); - } -} -- cgit