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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/// A file or folder path.
///
/// # Base Path and Relative Path
/// Storage paths are divided into a base path and a relative path. The base path is effectively
/// immutable. The relative path is a sequence of segments divided by file separators.
///
/// ```text
/// Unix Example:
/// Path: /the/path
/// Base Path: /
/// Relative Path: the/path
///
/// Windows Example:
/// Path: C:\The\Path
/// Base Path: C:\
/// Relative Path: The\Path
///
/// Cloudflare R2 Example:
/// Path: https://account.r2.cloudflarestorage.com/bucket/the/path
/// Base Path: https://account.r2.cloudflarestorage.com/bucket/
/// Relative Path: the/path
/// ```
///
/// # Files and Folders
/// A storage path can be a file path or a folder path. These are mutually exclusive and
/// exhaustive. A storage path is a folder path if it is equal to its base path or ends with a
/// file separator. Otherwise it is a file path. This invariant can be broken with `unsafe`.
///
/// # File Separators
/// - Windows paths use `\`. Unix and R2 paths use `/`.
/// - A Windows path never holds `/`. Parsing and appending turn each `/` into `\`. A path built
/// by appending then equals the same path parsed in one piece.
/// - Unix and R2 paths keep `\` as is. It is a valid character in their names.
/// - Like the file and folder rule, this can be broken with `unsafe`.
///
/// # Comparison
/// - Paths compare by their exact text.
/// - Letter case matters on Windows too. `C:\Foo` and `C:\foo` are not equal.