Esempio n. 1
0
func asyncGetFile(bucket *s3.Bucket, path string, fileData chan []byte) {
	go func() {
		data, getErr := bucket.Get(path)
		if getErr != nil {
			fileData <- nil
		} else {
			fileData <- data
		}
	}()
}
Esempio n. 2
0
// Get gets the s3 object at the specified path and saves to disk
// with its filename and a root prependeded
func Get(b *s3.Bucket, path string, root string) error {
	var conn Connection
	err := conn.Connect()
	if err != nil {
		return err
	}
	data, err := b.Get(path)
	if err != nil {
		panic(fmt.Sprintf("can't download %v \n ", err))
	}
	localpath := fmt.Sprintf("%v/%v", root, path)
	stripped := strings.Split(localpath, "/")
	pathonly := strings.Join(stripped[:len(stripped)-1], "/")
	err = os.MkdirAll(pathonly, 0777)
	if err != nil {
		return err
	}
	err = ioutil.WriteFile(localpath, data, 0666)
	if err != nil {
		return err
	}
	fmt.Printf("Downloaded: %v \n", localpath)
	return nil
}