-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathContentByteRangeInterval.cs
More file actions
70 lines (60 loc) · 1.88 KB
/
ContentByteRangeInterval.cs
File metadata and controls
70 lines (60 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System.Text;
namespace Waher.Networking.HTTP
{
/// <summary>
/// Represents a content range in a ranged HTTP request or response.
/// </summary>
public class ContentByteRangeInterval
{
private readonly long first;
private readonly long last;
private readonly long total;
/// <summary>
/// Represents a content range interval in a ranged HTTP request or response.
/// </summary>
/// <param name="First">First byte of interval.</param>
/// <param name="Last">Last byte of interval.</param>
/// <param name="Total">Total number of bytes of content entity.</param>
public ContentByteRangeInterval(long First, long Last, long Total)
{
this.first = First;
this.last = Last;
this.total = Total;
}
/// <summary>
/// First byte of interval.
/// </summary>
public long First => this.first;
/// <summary>
/// Last byte of interval, inclusive.
/// </summary>
public long Last => this.last;
/// <summary>
/// Total number of bytes of content entity.
/// </summary>
public long Total => this.total;
/// <inheritdoc/>
public override string ToString()
{
return ContentRangeToString(this.first, this.last, this.total);
}
/// <summary>
/// Converts the content range to an HTTP header field value string.
/// </summary>
/// <param name="First">First byte of content range.</param>
/// <param name="Last">Last byte of content range.</param>
/// <param name="Total">Total number of bytes of content entity.</param>
/// <returns>Content-Range HTTP header field value string.</returns>
public static string ContentRangeToString(long First, long Last, long Total)
{
StringBuilder Output = new StringBuilder();
Output.Append("bytes ");
Output.Append(First.ToString());
Output.Append('-');
Output.Append(Last.ToString());
Output.Append('/');
Output.Append(Total.ToString());
return Output.ToString();
}
}
}