github.com/weiwenhao/getter@v1.30.1/decompress_zstd.go (about) 1 package getter 2 3 import ( 4 "fmt" 5 "github.com/klauspost/compress/zstd" 6 "os" 7 "path/filepath" 8 ) 9 10 // ZstdDecompressor is an implementation of Decompressor that 11 // can decompress .zst files. 12 type ZstdDecompressor struct{} 13 14 func (d *ZstdDecompressor) Decompress(dst, src string, dir bool, umask os.FileMode) error { 15 if dir { 16 return fmt.Errorf("zstd-compressed files can only unarchive to a single file") 17 } 18 19 // If we're going into a directory we should make that first 20 if err := os.MkdirAll(filepath.Dir(dst), mode(0755, umask)); err != nil { 21 return err 22 } 23 24 // File first 25 f, err := os.Open(src) 26 if err != nil { 27 return err 28 } 29 defer f.Close() 30 31 // zstd compression is second 32 zstdR, err := zstd.NewReader(f) 33 if err != nil { 34 return err 35 } 36 defer zstdR.Close() 37 38 // Copy it out 39 return copyReader(dst, zstdR, 0622, umask) 40 }