@@ -66,6 +66,7 @@ var supportedKind = map[string]string{
6666 "hh" : "text/x-h" ,
6767 "html" : "" ,
6868 "java" : "text/x-java" ,
69+ "joblib" : "application/x-python-joblib" ,
6970 "js" : "application/javascript" ,
7071 "lnk" : "application/x-ms-shortcut" ,
7172 "lua" : "text/x-lua" ,
@@ -140,20 +141,6 @@ func makeFileType(path string, ext string, mime string) *FileType {
140141 return & FileType {MIME : "application/json" , Ext : ext }
141142 }
142143
143- // Capture joblib files that cannot be decompressed externally
144- // https://joblib.readthedocs.io/en/stable/generated/joblib.dump.html
145- joblibExts := []string {
146- "z" ,
147- "gz" ,
148- "bz2" ,
149- "xz" ,
150- "lzma" ,
151- }
152-
153- if slices .Contains (joblibExts , ext ) && mime == "application/octet-stream" {
154- return & FileType {MIME : "application/octet-stream" , Ext : ext }
155- }
156-
157144 if supportedKind [ext ] == "" {
158145 return nil
159146 }
@@ -193,8 +180,9 @@ func File(path string) (*FileType, error) {
193180 // first strategy: mimetype
194181 mtype , err := mimetype .DetectFile (path )
195182 if err == nil {
196- ft := makeFileType (path , GetExt (path ), mtype .String ())
197- return ft , nil
183+ if ft := makeFileType (path , mtype .Extension (), mtype .String ()); ft != nil {
184+ return ft , nil
185+ }
198186 }
199187
200188 // second strategy: path (extension, mostly)
@@ -249,6 +237,21 @@ func File(path string) (*FileType, error) {
249237 return Path (".gzip" ), nil
250238 case hdr [0 ] == '\x78' && hdr [1 ] == '\x5E' :
251239 return Path (".Z" ), nil
240+ // Capture joblib files that cannot be decompressed externally
241+ // https://joblib.readthedocs.io/en/stable/generated/joblib.dump.html
242+ // Check the header, file extension, and MIME type to be as specific as possible
243+ case hdr [0 ] == '\x5A' && hdr [1 ] == '\x46' && hdr [2 ] == '\x30' && hdr [3 ] == '\x78' :
244+ joblibExts := []string {
245+ ".z" ,
246+ ".gz" ,
247+ ".bz2" ,
248+ ".xz" ,
249+ ".lzma" ,
250+ }
251+
252+ if slices .Contains (joblibExts , GetExt (path )) && mtype .String () == "application/octet-stream" {
253+ return Path (".joblib" ), nil
254+ }
252255 }
253256 return nil , nil
254257}
0 commit comments