@@ -25,6 +25,7 @@ import (
2525 "math"
2626 "os"
2727 "path/filepath"
28+ "strings"
2829 "sync"
2930 "time"
3031
@@ -175,8 +176,13 @@ func (d *Downloader) DownloadDirectory(ctx context.Context, input *DownloadDirec
175176 inputs := make ([]DownloadObjectInput , 0 , len (objectsToQueue ))
176177
177178 for _ , object := range objectsToQueue {
178- objDirectory := filepath .Join (input .LocalDirectory , filepath .Dir (object ))
179- filePath := filepath .Join (input .LocalDirectory , object )
179+ objectWithoutPrefix := object
180+ if len (input .StripPrefix ) > 0 {
181+ objectWithoutPrefix , _ = strings .CutPrefix (object , input .StripPrefix )
182+ }
183+
184+ objDirectory := filepath .Join (input .LocalDirectory , filepath .Dir (objectWithoutPrefix ))
185+ filePath := filepath .Join (input .LocalDirectory , objectWithoutPrefix )
180186
181187 // Make sure all directories in the object path exist.
182188 err := os .MkdirAll (objDirectory , fs .ModeDir | fs .ModePerm )
@@ -750,6 +756,12 @@ type DownloadDirectoryInput struct {
750756 // The directory will be created if it does not already exist. Required.
751757 LocalDirectory string
752758
759+ // StripPrefix is a prefix to be removed from the path of the local file on
760+ // download from GCS. For example, if you have an object in GCS called
761+ // "mydirectory/a/file", and StripPrefix is set to "mydirectory/", the file
762+ // will be downloaded to "{LocalDirectory}/a/file". Optional.
763+ StripPrefix string
764+
753765 // Prefix is the prefix filter to download objects whose names begin with this.
754766 // Optional.
755767 Prefix string
0 commit comments