• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

JaCraig / Archivist / 19320779687

13 Nov 2025 04:42AM UTC coverage: 77.456% (-1.3%) from 78.739%
19320779687

push

github

JaCraig
feat(dependencies): update package versions

Update various package dependencies to their latest versions to ensure compatibility, security, and access to new features.

- Update `Microsoft.NET.Test.Sdk` to `18.0.1` in `Archivist.OCR.Tests.csproj` and `Archivist.Tests.csproj`.
- Update `Microsoft.CodeAnalysis.NetAnalyzers` to `10.0.100` in `Archivist.OCR.csproj` and `Archivist.csproj`.
- Update `Microsoft.Extensions.Logging` to `10.0.0` in `Archivist.Tests.csproj`.
- Update `Microsoft.Extensions.DependencyInjection` and `Microsoft.Extensions.Options` to `10.0.0` in `Archivist.csproj`.
- Update `ObjectCartographer` to `4.2.0` in `Archivist.csproj`.
- Update `System.Text.Encoding.CodePages` to `10.0.0` in `Archivist.csproj`.

2411 of 3412 branches covered (70.66%)

Branch coverage included in aggregate %.

3203 of 3836 relevant lines covered (83.5%)

6733.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.28
/Archivist/ExtensionMethods/InternalExtensionMethods.cs
1
using System;
2
using System.Buffers;
3
using System.IO;
4
using System.Text;
5
using System.Threading.Tasks;
6

7
namespace Archivist.ExtensionMethods
8
{
9
    /// <summary>
10
    /// Internal extension methods.
11
    /// </summary>
12
    public static class InternalExtensionMethods
13
    {
14
        /// <summary>
15
        /// Adds spaces before each capital letter in the input string.
16
        /// </summary>
17
        /// <param name="input">Input string</param>
18
        /// <returns>String with spaces before each capital letter</returns>
19
        public static string AddSpaces(this string? input)
20
        {
21
            if (string.IsNullOrWhiteSpace(input))
213✔
22
            {
23
                return "";
3✔
24
            }
25

26
            StringBuilder NewText = new StringBuilder(input.Length * 2).Append(input[0]);
210✔
27
            for (int X = 1, InputLength = input.Length; X < InputLength; ++X)
4,940✔
28
            {
29
                var CurrentChar = input[X];
2,155✔
30
                var PreviousChar = input[X - 1];
2,155✔
31
                if (char.IsUpper(CurrentChar) && !(char.IsWhiteSpace(PreviousChar) || char.IsUpper(PreviousChar)))
2,155✔
32
                {
33
                    _ = NewText.Append(' ');
154✔
34
                }
35
                _ = NewText.Append(CurrentChar);
2,155✔
36
            }
37
            return NewText.ToString();
210✔
38
        }
39

40
        /// <summary>
41
        /// Formats a string using the specified format.
42
        /// </summary>
43
        /// <param name="input">Input string</param>
44
        /// <param name="format">Format to use</param>
45
        /// <returns>The formatted string</returns>
46
        public static string FormatString(this string? input, string format)
47
        {
48
            if (string.IsNullOrEmpty(format) || !InternalStringFormatter.IsValid(format))
49✔
49
            {
50
                throw new ArgumentException("Format is not valid.", nameof(format));
3✔
51
            }
52
            return InternalStringFormatter.Format(input, format);
46✔
53
        }
54

55
        /// <summary>
56
        /// Gets the first x number of characters from the left hand side
57
        /// </summary>
58
        /// <param name="input">Input string</param>
59
        /// <param name="length">x number of characters to return</param>
60
        /// <returns>The resulting string</returns>
61
        public static string Left(this string? input, int length)
62
        {
63
            return length <= 0
104✔
64
                ? ""
104✔
65
                : string.IsNullOrEmpty(input) ? "" : input[..(input.Length > length ? length : input.Length)];
104✔
66
        }
67

68
        /// <summary>
69
        /// Takes all of the data in the stream and returns it as a string
70
        /// </summary>
71
        /// <param name="input">Input stream</param>
72
        /// <param name="encodingUsing">The encoding to return as</param>
73
        /// <returns>The resulting string</returns>
74
        public static string ReadAll(this Stream? input, Encoding? encodingUsing = null)
75
        {
76
            if (input is null)
8✔
77
                return "";
2✔
78
            return input.ReadAllBinary().ToString(encodingUsing) ?? "";
6!
79
        }
80

81
        /// <summary>
82
        /// Takes all of the data in the stream and returns it as a string
83
        /// </summary>
84
        /// <param name="input">Input stream</param>
85
        /// <param name="encodingUsing">Encoding that the string should be in (defaults to UTF8)</param>
86
        /// <returns>A string containing the content of the stream</returns>
87
        public static async Task<string> ReadAllAsync(this Stream? input, Encoding? encodingUsing = null)
88
        {
89
            if (input is null)
29✔
90
                return "";
2✔
91
            return (await input.ReadAllBinaryAsync().ConfigureAwait(false)).ToString(encodingUsing) ?? "";
27!
92
        }
29✔
93

94
        /// <summary>
95
        /// Takes all of the data in the stream and returns it as an array of bytes
96
        /// </summary>
97
        /// <param name="input">Input stream</param>
98
        /// <returns>A byte array</returns>
99
        public static byte[] ReadAllBinary(this Stream? input)
100
        {
101
            if (input is null)
12✔
102
                return Array.Empty<byte>();
2✔
103

104
            if (input is MemoryStream TempInput)
10✔
105
                return TempInput.ToArray();
6✔
106

107
            ArrayPool<byte> Pool = ArrayPool<byte>.Shared;
4✔
108
            var Buffer = Pool.Rent(4096);
4✔
109
            using var Temp = new MemoryStream();
4✔
110
            while (true)
111
            {
112
                try
113
                {
114
                    var Count = input.Read(Buffer);
111✔
115
                    if (Count <= 0)
111✔
116
                        break;
4✔
117
                    Temp.Write(Buffer, 0, Count);
107✔
118
                }
107✔
119
                catch
×
120
                {
121
                    break;
×
122
                }
123
            }
124
            Pool.Return(Buffer);
4✔
125
            return Temp.ToArray();
4✔
126
        }
4✔
127

128
        /// <summary>
129
        /// Takes all of the data in the stream and returns it as an array of bytes
130
        /// </summary>
131
        /// <param name="input">Input stream</param>
132
        /// <returns>A byte array</returns>
133
        public static async Task<byte[]> ReadAllBinaryAsync(this Stream? input)
134
        {
135
            if (input is null)
30✔
136
                return Array.Empty<byte>();
2✔
137

138
            if (input is MemoryStream TempInput)
28✔
139
                return TempInput.ToArray();
19✔
140

141
            ArrayPool<byte> Pool = ArrayPool<byte>.Shared;
9✔
142
            var Buffer = Pool.Rent(4096);
9✔
143
            await using var Temp = new MemoryStream();
9✔
144
            while (true)
145
            {
146
                try
147
                {
148
                    var Count = await input.ReadAsync(Buffer.AsMemory(0, Buffer.Length)).ConfigureAwait(false);
55✔
149
                    if (Count <= 0)
55✔
150
                        break;
9✔
151
                    Temp.Write(Buffer, 0, Count);
46✔
152
                }
46✔
153
                catch
×
154
                {
155
                    break;
×
156
                }
157
            }
158
            Pool.Return(Buffer);
9✔
159
            return Temp.ToArray();
9✔
160
        }
30✔
161

162
        /// <summary>
163
        /// Strips illegal characters from RSS items
164
        /// </summary>
165
        /// <param name="original">Original text</param>
166
        /// <returns>string stripped of certain characters.</returns>
167
        public static string StripIllegalCharacters(this string? original)
168
        {
169
            return original?.Replace("&nbsp;", " ")
15,337✔
170
                .Replace("&#160;", string.Empty)
15,337✔
171
                .Trim()
15,337✔
172
                .Replace("&", "and") ?? "";
15,337✔
173
        }
174

175
        /// <summary>
176
        /// Converts a string to a byte array using the specified encoding.
177
        /// </summary>
178
        /// <param name="input">The input string</param>
179
        /// <param name="encodingUsing">The encoding to use (defaults to UTF8)</param>
180
        /// <returns>The resulting byte array</returns>
181
        public static byte[] ToByteArray(this string? input, Encoding? encodingUsing = null)
182
        {
183
            if (string.IsNullOrEmpty(input))
9✔
184
                return Array.Empty<byte>();
1✔
185

186
            encodingUsing ??= Encoding.UTF8;
8✔
187
            return encodingUsing.GetBytes(input);
8✔
188
        }
189

190
        /// <summary>
191
        /// Converts a byte array to a string
192
        /// </summary>
193
        /// <param name="input">Input byte array</param>
194
        /// <param name="encodingUsing">Encoding that the string should be in (defaults to UTF8)</param>
195
        /// <param name="index">Index to start at</param>
196
        /// <param name="count">Number of bytes to convert</param>
197
        /// <returns>A string containing the content of the byte array</returns>
198
        public static string ToString(this byte[]? input, Encoding? encodingUsing, int index = 0, int count = -1)
199
        {
200
            if (input is null)
36✔
201
                return "";
2✔
202

203
            if (count == -1)
34✔
204
                count = input.Length - index;
34✔
205

206
            encodingUsing ??= Encoding.UTF8;
34✔
207
            return encodingUsing.GetString(input, index, count);
34✔
208
        }
209
    }
210
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc