forked from snowflakedb/gosnowflake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_compression_type.go
132 lines (123 loc) · 2.33 KB
/
file_compression_type.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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Copyright (c) 2021-2022 Snowflake Computing Inc. All rights reserved.
package gosnowflake
import (
"bytes"
"strings"
"github.com/gabriel-vasile/mimetype"
)
type compressionType struct {
name string
fileExtension string
mimeSubtypes []string
isSupported bool
}
var compressionTypes = map[string]*compressionType{
"GZIP": {
"GZIP",
".gz",
[]string{"gzip", "x-gzip"},
true,
},
"DEFLATE": {
"DEFLATE",
".deflate",
[]string{"zlib", "deflate"},
true,
},
"RAW_DEFLATE": {
"RAW_DEFLATE",
".raw_deflate",
[]string{"raw_deflate"},
true,
},
"BZIP2": {
"BZIP2",
".bz2",
[]string{"bzip2", "x-bzip2", "x-bz2", "x-bzip", "bz2"},
true,
},
"LZIP": {
"LZIP",
".lz",
[]string{"lzip", "x-lzip"},
false,
},
"LZMA": {
"LZMA",
".lzma",
[]string{"lzma", "x-lzma"},
false,
},
"LZO": {
"LZO",
".lzo",
[]string{"lzo", "x-lzo"},
false,
},
"XZ": {
"XZ",
".xz",
[]string{"xz", "x-xz"},
false,
},
"COMPRESS": {
"COMPRESS",
".Z",
[]string{"compress", "x-compress"},
false,
},
"PARQUET": {
"PARQUET",
".parquet",
[]string{"parquet"},
true,
},
"ZSTD": {
"ZSTD",
".zst",
[]string{"zstd", "x-zstd"},
true,
},
"BROTLI": {
"BROTLI",
".br",
[]string{"br", "x-br"},
true,
},
"ORC": {
"ORC",
".orc",
[]string{"orc"},
true,
},
}
var mimeSubTypeToCompression map[string]*compressionType
var extensionToCompression map[string]*compressionType
func init() {
mimeSubTypeToCompression = make(map[string]*compressionType)
extensionToCompression = make(map[string]*compressionType)
for _, meta := range compressionTypes {
extensionToCompression[meta.fileExtension] = meta
for _, subtype := range meta.mimeSubtypes {
mimeSubTypeToCompression[subtype] = meta
}
}
mimetype.Extend(func(raw []byte, limit uint32) bool {
return bytes.HasPrefix(raw, []byte("PAR1"))
}, "snowflake/parquet", ".parquet")
mimetype.Extend(func(raw []byte, limit uint32) bool {
return bytes.HasPrefix(raw, []byte("ORC"))
}, "snowflake/orc", ".orc")
}
func lookupByMimeSubType(mimeSubType string) *compressionType {
if val, ok := mimeSubTypeToCompression[strings.ToLower(mimeSubType)]; ok {
return val
}
return nil
}
func lookupByExtension(extension string) *compressionType {
if val, ok := extensionToCompression[strings.ToLower(extension)]; ok {
return val
}
return nil
}