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

neon-sunset / U8String / 6005516171

28 Aug 2023 10:17PM UTC coverage: 17.791% (-0.3%) from 18.096%
6005516171

push

github

neon-sunset
feat: add construction overloads for streams and file handles

134 of 1066 branches covered (0.0%)

Branch coverage included in aggregate %.

97 of 97 new or added lines in 3 files covered. (100.0%)

478 of 2374 relevant lines covered (20.13%)

34680.8 hits per line

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

0.0
/src/Extensions/IO/U8FileExtensions.cs
1
using Microsoft.Win32.SafeHandles;
2

3
namespace U8Primitives.IO;
4

5
public static class U8FileExtensions
6
{
7
    public static U8String ReadToU8String(this SafeFileHandle handle, long offset = 0)
8
    {
9
        var length = RandomAccess.GetLength(handle) - offset;
×
10
        if (length > int.MaxValue)
×
11
        {
12
            ThrowHelpers.ArgumentOutOfRange();
×
13
        }
14
        
15
        if (length > 0)
×
16
        {
17
            var buffer = new byte[(int)length];
×
18
            var bytesRead = RandomAccess.Read(handle, buffer, offset);
×
19

20
            U8String.Validate(buffer.SliceUnsafe(0, bytesRead));
×
21
            return new U8String(buffer, 0, bytesRead);
×
22
        }
23

24
        return default;
×
25
    }
26

27
    public static async Task<U8String> ReadToU8StringAsync(
28
        this SafeFileHandle handle,
29
        long offset = 0,
30
        CancellationToken ct = default)
31
    {
32
        var length = RandomAccess.GetLength(handle) - offset;
×
33
        if (length > int.MaxValue)
×
34
        {
35
            ThrowHelpers.ArgumentOutOfRange();
×
36
        }
37
        
38
        if (length > 0)
×
39
        {
40
            var buffer = new byte[(int)length];
×
41
            var bytesRead = await RandomAccess.ReadAsync(handle, buffer, offset, ct);
×
42

43
            U8String.Validate(buffer.SliceUnsafe(0, bytesRead));
×
44
            return new U8String(buffer, 0, bytesRead);
×
45
        }
46

47
        return default;
×
48
    }
×
49
}
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