aboutsummaryrefslogtreecommitdiff
path: root/lib/Utils/src/IO
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2023-08-27 14:14:51 -0400
committerLibravatar vnugent <public@vaughnnugent.com>2023-08-27 14:14:51 -0400
commit87df3ec1f0f87167853b197f66cefb48855df9ac (patch)
tree01f386c74e314470a97722e69b6748cf4cb4154a /lib/Utils/src/IO
parentf541b853c738a076d2a85ef6b269c1b140353b85 (diff)
spelling, and tiny tweaks
Diffstat (limited to 'lib/Utils/src/IO')
-rw-r--r--lib/Utils/src/IO/IStreamBufferFactory.cs4
-rw-r--r--lib/Utils/src/IO/IsolatedStorageDirectory.cs4
-rw-r--r--lib/Utils/src/IO/VnStreamReader.cs70
3 files changed, 39 insertions, 39 deletions
diff --git a/lib/Utils/src/IO/IStreamBufferFactory.cs b/lib/Utils/src/IO/IStreamBufferFactory.cs
index f8cfe2d..5aab76b 100644
--- a/lib/Utils/src/IO/IStreamBufferFactory.cs
+++ b/lib/Utils/src/IO/IStreamBufferFactory.cs
@@ -3,9 +3,9 @@
*
* Library: VNLib
* Package: VNLib.Utils
-* File: VnStreamReader.cs
+* File: IStreamBufferFactory.cs
*
-* VnStreamReader.cs is part of VNLib.Utils which is part of the larger
+* IStreamBufferFactory.cs is part of VNLib.Utils which is part of the larger
* VNLib collection of libraries and utilities.
*
* VNLib.Utils is free software: you can redistribute it and/or modify
diff --git a/lib/Utils/src/IO/IsolatedStorageDirectory.cs b/lib/Utils/src/IO/IsolatedStorageDirectory.cs
index 65460ff..c06018e 100644
--- a/lib/Utils/src/IO/IsolatedStorageDirectory.cs
+++ b/lib/Utils/src/IO/IsolatedStorageDirectory.cs
@@ -126,9 +126,13 @@ namespace VNLib.Utils.IO
Storage.DeleteDirectory(this.DirectoryPath);
}
+ ///<inheritdoc/>
public override long AvailableFreeSpace => Storage.AvailableFreeSpace;
+ ///<inheritdoc/>
public override long Quota => Storage.Quota;
+ ///<inheritdoc/>
public override long UsedSize => Storage.UsedSize;
+ ///<inheritdoc/>
public override bool IncreaseQuotaTo(long newQuotaSize) => Storage.IncreaseQuotaTo(newQuotaSize);
/// <summary>
diff --git a/lib/Utils/src/IO/VnStreamReader.cs b/lib/Utils/src/IO/VnStreamReader.cs
index a03a1de..22df5c7 100644
--- a/lib/Utils/src/IO/VnStreamReader.cs
+++ b/lib/Utils/src/IO/VnStreamReader.cs
@@ -107,28 +107,12 @@ namespace VNLib.Utils.IO
///<inheritdoc/>
public override async Task<string?> ReadLineAsync()
{
+ string? result = null;
+
//If buffered data is available, check for line termination
- if (Available > 0)
+ if (Available > 0 && GetStringFromBuffer(ref result))
{
- //Get current buffer window
- Memory<byte> buffered = _buffer.AccumulatedBuffer;
-
- //search for line termination in current buffer
- int term = buffered.IndexOf(LineTermination);
-
- //Termination found in buffer window
- if (term > -1)
- {
- //Capture the line from the begining of the window to the termination
- Memory<byte> line = buffered[..term];
-
- //Shift the window to the end of the line (excluding the termination)
- _buffer.AdvanceStart(term + LineTermination.Length);
-
- //Decode the line to a string
- return Encoding.GetString(line.Span);
- }
- //Termination not found
+ return result;
}
//Compact the buffer window and see if space is avialble to buffer more data
@@ -143,24 +127,11 @@ namespace VNLib.Utils.IO
//No string found
return null;
}
-
- //Get current buffer window
- Memory<byte> buffered = _buffer.AccumulatedBuffer;
-
- //search for line termination in current buffer
- int term = buffered.IndexOf(LineTermination);
-
- //Termination found in buffer window
- if (term > -1)
+
+ //Termination not found
+ if (GetStringFromBuffer(ref result))
{
- //Capture the line from the begining of the window to the termination
- Memory<byte> line = buffered[..term];
-
- //Shift the window to the end of the line (excluding the termination)
- _buffer.AdvanceStart(term + LineTermination.Length);
-
- //Decode the line to a string
- return Encoding.GetString(line.Span);
+ return result;
}
}
//Termination not found within the entire buffer, so buffer space has been exhausted
@@ -170,6 +141,31 @@ namespace VNLib.Utils.IO
throw new OutOfMemoryException("A line termination was not found within the buffer");
#pragma warning restore CA2201 // Do not raise reserved exception types
}
+
+ private bool GetStringFromBuffer(ref string? result)
+ {
+ //Get current buffer window
+ Memory<byte> buffered = _buffer.AccumulatedBuffer;
+
+ //search for line termination in current buffer
+ int term = buffered.IndexOf(LineTermination);
+
+ //Termination found in buffer window
+ if (term > -1)
+ {
+ //Capture the line from the begining of the window to the termination
+ Memory<byte> line = buffered[..term];
+
+ //Shift the window to the end of the line (excluding the termination)
+ _buffer.AdvanceStart(term + LineTermination.Length);
+
+ //Decode the line to a string
+ result = Encoding.GetString(line.Span);
+ return true;
+ }
+
+ return false;
+ }
///<inheritdoc/>
public override int Read(char[] buffer, int index, int count) => Read(buffer.AsSpan(index, count));