Esempio n. 1
0
// get a single file from the s3 bucket
func (remote *S3Remote) getFile(dst string, key *keyDef) error {
	log.Printf("Pulling key %s (%s)\n", key.key, utils.HumanSize(key.s3Key.Size))

	from, _, err := remote.getUploadDownloadBucket().GetReader(key.key, nil)
	if err != nil {
		return err
	}
	defer from.Close()

	if err := os.MkdirAll(filepath.Dir(dst), 0700); err != nil {
		return err
	}

	to, err := os.Create(dst)
	if err != nil {
		return err
	}

	progressReader := utils.NewProgressReader(from, key.s3Key.Size, key.key)

	_, err = io.Copy(to, progressReader)
	if err != nil {
		return err
	}

	return nil
}
Esempio n. 2
0
// put a file with key from imageRoot to the s3 bucket
func (remote *S3Remote) putFile(src string, key *keyDef) error {
	dstKey := remote.remoteKey(key.key)

	f, err := os.Open(src)
	if err != nil {
		return err
	}
	defer f.Close()

	finfo, err := f.Stat()
	if err != nil {
		return err
	}

	progressReader := utils.NewProgressReader(f, finfo.Size(), src)

	// Open a PutWriter for actual file upload
	w, err := remote.getUploadDownloadBucket().PutWriter(dstKey, nil, nil)
	if err != nil {
		return err
	}
	if _, err = io.Copy(w, progressReader); err != nil { // Copy to S3
		return err
	}
	if err = w.Close(); err != nil {
		return err
	}

	return nil
}