-
Notifications
You must be signed in to change notification settings - Fork 110
/
mime.go
57 lines (43 loc) · 1.68 KB
/
mime.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
package utils
import (
"fmt"
"strings"
)
const (
// MimeTypeSuffixLazy is used to indicate a lazy loading of data.
MimeTypeSuffixLazy = "lazy"
// MimeTypeRawRGBA is for go's internal image.NRGBA. This uses the custom header as
// explained in the comments for rimage.DecodeImage and rimage.EncodeImage.
MimeTypeRawRGBA = "image/vnd.viam.rgba"
// MimeTypeRawRGBALazy is a lazy MimeTypeRawRGBA.
MimeTypeRawRGBALazy = MimeTypeRawRGBA + "+" + MimeTypeSuffixLazy
// MimeTypeRawDepth is for depth images.
MimeTypeRawDepth = "image/vnd.viam.dep"
// MimeTypeJPEG is regular jpgs.
MimeTypeJPEG = "image/jpeg"
// MimeTypePNG is regular pngs.
MimeTypePNG = "image/png"
// MimeTypePCD is for .pcd pountcloud files.
MimeTypePCD = "pointcloud/pcd"
// MimeTypeQOI is for .qoi "Quite OK Image" for lossless, fast encoding/decoding.
MimeTypeQOI = "image/qoi"
// MimeTypeTabular used to indicate tabular data, this is used mainly for filtering data.
MimeTypeTabular = "x-application/tabular"
// MimeTypeDefault used if mimetype cannot be inferred.
MimeTypeDefault = "application/octet-stream"
)
// WithLazyMIMEType attaches the lazy suffix to a MIME.
func WithLazyMIMEType(mimeType string) string {
if _, has := CheckLazyMIMEType(mimeType); has {
return mimeType
}
return fmt.Sprintf("%s+%s", mimeType, MimeTypeSuffixLazy)
}
const lazyMIMESuffixCheck = "+" + MimeTypeSuffixLazy
// CheckLazyMIMEType checks the lazy suffix of a MIME.
func CheckLazyMIMEType(mimeType string) (string, bool) {
if strings.Count(mimeType, lazyMIMESuffixCheck) == 1 && strings.HasSuffix(mimeType, lazyMIMESuffixCheck) {
return strings.TrimSuffix(mimeType, lazyMIMESuffixCheck), true
}
return mimeType, false
}