github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/cmn/cos/basename.go (about) 1 // Package cos provides common low-level types and utilities for all aistore projects 2 /* 3 * Copyright (c) 2018-2023, NVIDIA CORPORATION. All rights reserved. 4 */ 5 package cos 6 7 import ( 8 "os" 9 "path/filepath" 10 "strings" 11 ) 12 13 // See also: cmn/archive/mime.go & ext/dsort/shard/record.go 14 15 // e.g.: "/aaa/bbb/ccc.tar.gz" => ".tar.gz", while "/aaa/bb.b/ccctargz" => "" 16 func Ext(path string) (ext string) { 17 for i := len(path) - 1; i >= 0 && !os.IsPathSeparator(path[i]); i-- { 18 if path[i] == '.' { 19 ext = path[i:] 20 } 21 } 22 return 23 } 24 25 // WebDataset convention - not to confuse with filepath.Base (!) 26 // * see https://github.com/webdataset/webdataset#the-webdataset-format 27 func WdsKey(path string) (key string) { 28 key = strings.TrimSuffix(path, filepath.Ext(path)) 29 if key != "" && key[0] == '/' { 30 key = key[1:] 31 } 32 return key 33 }