aboutsummaryrefslogtreecommitdiff
path: root/lib/VNLib.Plugins.Extensions.Data/src/Storage/Blob.cs
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2024-07-28 18:52:54 -0400
committerLibravatar vnugent <public@vaughnnugent.com>2024-07-28 18:52:54 -0400
commit641bdbe75cb0128c09e27f1b92709c86574026ac (patch)
treeeb412bcb9fa0442d2e283c54d207204034fcbe11 /lib/VNLib.Plugins.Extensions.Data/src/Storage/Blob.cs
parent1350c983c371fdd6a93596c8474345f9168284e1 (diff)
Squashed commit of the following:
commit 87887c0a45c84458e81fa38f7f4dca31faa49d7c Author: vnugent <public@vaughnnugent.com> Date: Sat Jul 27 22:41:17 2024 -0400 package updates commit d52772c010b10357d194239056d19c0d22d414fe Author: vnugent <public@vaughnnugent.com> Date: Sat Jul 27 20:50:12 2024 -0400 update secrets and remove deprecated and unused apis commit c8567e58dc1d4135da1f6cefa6fa66af5fcd7b19 Author: vnugent <public@vaughnnugent.com> Date: Mon Jul 15 19:05:01 2024 -0400 feat: Smiplify configuration helpers commit 640ee6760c07b628529e3160c16641773c76e800 Author: vnugent <public@vaughnnugent.com> Date: Thu Jul 4 23:02:56 2024 -0400 package updates commit db5747a20600a2e2c5e8d915cf0bdbe4ec6df6a2 Author: vnugent <public@vaughnnugent.com> Date: Fri Jun 21 17:08:16 2024 -0400 configuration validation updates commit 9bc24801735884e0c03aa00e83804448c466bdf2 Author: vnugent <public@vaughnnugent.com> Date: Sun Jun 16 13:16:18 2024 -0400 update plugins array instead of single path commit 1229ed75549de1c56aaee42c921acbd96c4d4c9b Author: vnugent <public@vaughnnugent.com> Date: Tue Jun 11 22:13:58 2024 -0400 feat: Stage some mvc stuff commit 35815081df2149741a6a79a880a57d63c5938a34 Author: vnugent <public@vaughnnugent.com> Date: Sun Jun 9 13:06:45 2024 -0400 package updates commit bcbe51bef546458cb7fee0d8f1dfd00cf936545a Author: vnugent <public@vaughnnugent.com> Date: Fri Jun 7 22:03:19 2024 -0400 feat: Allow S3Config type inheritence commit 2e55ac437f44eb5f9d66f7d7fd47b5670dedc2cb Merge: 27fb538 1350c98 Author: vnugent <public@vaughnnugent.com> Date: Wed May 22 15:29:47 2024 -0400 Merge branch 'master' into develop commit 27fb5382d80d9bcfb4c65974bbae20c5e7b8ccbc Author: vnugent <public@vaughnnugent.com> Date: Wed May 22 00:57:34 2024 -0400 feat: Vault environment vars commit 69f13e43dfdd8069459800ccc3039f45fc884814 Author: vnugent <public@vaughnnugent.com> Date: Wed May 15 22:04:43 2024 -0400 fix: #3 Defer vault loading until a secret actually needs it commit c848787d4830a73e9ba93898897282be2f3752f2 Author: vnugent <public@vaughnnugent.com> Date: Wed May 15 22:02:02 2024 -0400 package updates commit 21c6c85f540740ac29536a7091346a731aa85148 Author: vnugent <public@vaughnnugent.com> Date: Wed May 15 22:01:16 2024 -0400 fix: #3 Error raised when managed password type disposed commit 8e77289041349b16536497f48f0c0a4ec6fe30f5 Author: vnugent <public@vaughnnugent.com> Date: Thu May 2 15:44:42 2024 -0400 feat: #2 Middleware helpers, proj cleanup, fix sync secrets, vault client commit e0a5c85297516188e57b54d9b530b2482cb03eb0 Merge: a977dab 5ad520e Author: vnugent <public@vaughnnugent.com> Date: Sat Apr 27 17:44:09 2024 -0400 Merge branch 'master' into develop commit a977dabef1dec915e00f755cb3ee3363aa9985f1 Author: vnugent <public@vaughnnugent.com> Date: Sat Apr 27 17:26:35 2024 -0400 chore: package updates commit a2e2c3c4152d000b8df25c3c3fee14d491aab2c6 Merge: f03b727 87bfa83 Author: vnugent <public@vaughnnugent.com> Date: Sat Apr 20 12:11:45 2024 -0400 Merge branch 'master' into develop commit f03b727d8f8e52f1dbd6293ea5c5a492c6d8e2da Author: vnugent <public@vaughnnugent.com> Date: Sat Apr 20 12:02:07 2024 -0400 chore: Package updates
Diffstat (limited to 'lib/VNLib.Plugins.Extensions.Data/src/Storage/Blob.cs')
-rw-r--r--lib/VNLib.Plugins.Extensions.Data/src/Storage/Blob.cs245
1 files changed, 0 insertions, 245 deletions
diff --git a/lib/VNLib.Plugins.Extensions.Data/src/Storage/Blob.cs b/lib/VNLib.Plugins.Extensions.Data/src/Storage/Blob.cs
deleted file mode 100644
index 0edf653..0000000
--- a/lib/VNLib.Plugins.Extensions.Data/src/Storage/Blob.cs
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
-* Copyright (c) 2023 Vaughn Nugent
-*
-* Library: VNLib
-* Package: VNLib.Plugins.Extensions.Data
-* File: Blob.cs
-*
-* Blob.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;
-using System.IO;
-using System.Threading;
-using System.Threading.Tasks;
-using System.Runtime.Versioning;
-
-using VNLib.Utils;
-using VNLib.Utils.IO;
-using VNLib.Utils.Async;
-
-namespace VNLib.Plugins.Extensions.Data.Storage
-{
- /// <summary>
- /// Represents a stream of arbitrary binary data
- /// </summary>
- public class Blob : BackingStream<FileStream>, IObjectStorage, IAsyncExclusiveResource
- {
- protected readonly LWStorageDescriptor Descriptor;
-
- /// <summary>
- /// The current blob's unique ID
- /// </summary>
- public string BlobId => Descriptor.DescriptorID;
- /// <summary>
- /// A value indicating if the <see cref="Blob"/> has been modified
- /// </summary>
- public bool Modified { get; protected set; }
- /// <summary>
- /// A valid indicating if the blob was flagged for deletiong
- /// </summary>
- public bool Deleted { get; protected set; }
-
- /// <summary>
- /// The name of the file (does not change the actual file system name)
- /// </summary>
- public string Name
- {
- get => Descriptor.GetName();
- set => Descriptor.SetName(value);
- }
- /// <summary>
- /// The UTC time the <see cref="Blob"/> was last modified
- /// </summary>
- public DateTimeOffset LastWriteTimeUtc => Descriptor.LastModified;
- /// <summary>
- /// The UTC time the <see cref="Blob"/> was created
- /// </summary>
- public DateTimeOffset CreationTimeUtc => Descriptor.Created;
-
- internal Blob(LWStorageDescriptor descriptor, in FileStream file)
- {
- this.Descriptor = descriptor;
- base.BaseStream = file;
- }
-
- /// <summary>
- /// Prevents other processes from reading from or writing to the <see cref="Blob"/>
- /// </summary>
- /// <param name="position">The begining position of the range to lock</param>
- /// <param name="length">The range to be locked</param>
- /// <exception cref="IOException"></exception>
- /// <exception cref="ObjectDisposedException"></exception>
- /// <exception cref="ArgumentOutOfRangeException"></exception>
- [UnsupportedOSPlatform("ios")]
- [UnsupportedOSPlatform("macos")]
- [UnsupportedOSPlatform("tvos")]
- public void Lock(long position, long length) => BaseStream.Lock(position, length);
- /// <summary>
- /// Prevents other processes from reading from or writing to the <see cref="Blob"/>
- /// </summary>
- /// <exception cref="IOException"></exception>
- /// <exception cref="ObjectDisposedException"></exception>
- /// <exception cref="ArgumentOutOfRangeException"></exception>
- [UnsupportedOSPlatform("ios")]
- [UnsupportedOSPlatform("macos")]
- [UnsupportedOSPlatform("tvos")]
- public void Lock() => BaseStream.Lock(0, BaseStream.Length);
- /// <summary>
- /// Allows access by other processes to all or part of the <see cref="Blob"/> that was previously locked
- /// </summary>
- /// <param name="position">The begining position of the range to unlock</param>
- /// <param name="length">The range to be unlocked</param>
- /// <exception cref="ArgumentOutOfRangeException"></exception>
- [UnsupportedOSPlatform("ios")]
- [UnsupportedOSPlatform("macos")]
- [UnsupportedOSPlatform("tvos")]
- public void Unlock(long position, long length) => BaseStream.Unlock(position, length);
- /// <summary>
- /// Allows access by other processes to the entire <see cref="Blob"/>
- /// </summary>
- /// <exception cref="ArgumentOutOfRangeException"></exception>
- [UnsupportedOSPlatform("ios")]
- [UnsupportedOSPlatform("macos")]
- [UnsupportedOSPlatform("tvos")]
- public void Unlock() => BaseStream.Unlock(0, BaseStream.Length);
- ///<inheritdoc/>
- public override void SetLength(long value)
- {
- base.SetLength(value);
- //Set modified flag
- Modified |= true;
- }
-
- /*
- * Capture on-write calls to set the modified flag
- */
- ///<inheritdoc/>
- protected override void OnWrite(int count) => Modified |= true;
-
- T IObjectStorage.GetObject<T>(string key) => ((IObjectStorage)Descriptor).GetObject<T>(key);
- void IObjectStorage.SetObject<T>(string key, T obj) => ((IObjectStorage)Descriptor).SetObject(key, obj);
-
- public string this[string index]
- {
- get => Descriptor[index];
- set => Descriptor[index] = value;
- }
-
-
- /// <summary>
- /// Marks the file for deletion and will be deleted when the <see cref="Blob"/> is disposed
- /// </summary>
- public void Delete()
- {
- //Set deleted flag
- Deleted |= true;
- Descriptor.Delete();
- }
- ///<inheritdoc/>
- public bool IsReleased => Descriptor.IsReleased;
-
-
- /// <summary>
- /// <para>
- /// If the <see cref="Blob"/> was opened with writing enabled,
- /// and file was modified, changes are flushed to the backing store
- /// and the stream is set to readonly.
- /// </para>
- /// <para>
- /// If calls to this method succeed the stream is placed into a read-only mode
- /// which will cause any calls to Write to throw a <see cref="NotSupportedException"/>
- /// </para>
- /// </summary>
- /// <returns>A <see cref="ValueTask"/> that may be awaited until the operation completes</returns>
- /// <remarks>
- /// This method may be called to avoid flushing changes to the backing store
- /// when the <see cref="Blob"/> is disposed (i.e. lifetime is manged outside of the desired scope)
- /// </remarks>
- /// <exception cref="IOException"></exception>
- /// <exception cref="ObjectDisposedException"></exception>
- /// <exception cref="InvalidOperationException"></exception>
- public async ValueTask FlushChangesAndSetReadonlyAsync()
- {
- if (Deleted)
- {
- throw new InvalidOperationException("The blob has been deleted and must be closed!");
- }
- if (Modified)
- {
- //flush the base stream
- await BaseStream.FlushAsync();
- //Update the file length in the store
- Descriptor.SetLength(BaseStream.Length);
- }
- //flush changes, this will cause the dispose method to complete synchronously when closing
- await Descriptor.WritePendingChangesAsync();
- //Clear modified flag
- Modified = false;
- //Set to readonly mode
- base.ForceReadOnly = true;
- }
-
-
- /*
- * Override the dispose async to manually dispose the
- * base stream and avoid the syncrhonous (OnClose)
- * method and allow awaiting the descriptor release
- */
- ///<inheritdoc/>
- public override async ValueTask DisposeAsync()
- {
- await ReleaseAsync();
- GC.SuppressFinalize(this);
- }
- ///<inheritdoc/>
- public async ValueTask ReleaseAsync(CancellationToken cancellation = default)
- {
- try
- {
- //Check for deleted
- if (Deleted)
- {
- //Dispose the base stream explicitly
- await BaseStream.DisposeAsync();
- //Try to delete the file
- File.Delete(BaseStream.Name);
- }
- //Check to see if the file was modified
- else if (Modified)
- {
- //Set the file size in bytes
- Descriptor.SetLength(BaseStream.Length);
- }
- }
- catch
- {
- //Set the error flag
- Descriptor.IsError(true);
- //propagate the exception
- throw;
- }
- finally
- {
- //Dispose the stream
- await BaseStream.DisposeAsync();
- //Release the descriptor
- await Descriptor.ReleaseAsync(cancellation);
- }
- }
- }
-} \ No newline at end of file