-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileuri.go
57 lines (53 loc) · 1.05 KB
/
fileuri.go
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
// Copyright 2022 cloudeng llc. All rights reserved.
// Use of this source code is governed by the Apache-2.0
// license that can be found in the LICENSE file.
package cloudpath
import (
"strings"
)
// called for urls of the form, but with the file:// prefix removed.
//
// Unix:
// file://localhost/etc/fstab
// file:///etc/fstab
//
// Windows:
// file://localhost/c:/WINDOWS/clock.avi
// file:///c:/WINDOWS/clock.avi
func parseFileURI(p string) (host, rest, drive string) {
idx := strings.Index(p, "/")
if idx < 0 {
// file://xxx is not matched.
return "", "", ""
}
host = p[:idx]
rest = p[idx:]
if d, ok := isWindowsDrive(p[idx+1:]); ok {
rest = rest[1:]
drive = d
}
return
}
// return the bucket and key from /bucket/key...
func bucketAndKey(path string) (bucket, key string) {
p := path
switch len(path) {
case 0:
return
case 1:
if path[0] == '/' {
return
}
default:
if path[0] == '/' {
p = p[1:]
}
}
// p is now bucket/key...
idx := strings.Index(p, "/")
if idx < 0 {
bucket = p
return
}
return p[:idx], p[idx:]
}