Skip to content

Instantly share code, notes, and snippets.

@harshavardhana
Created October 20, 2017 01:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harshavardhana/0a1dc2939c7453c43287a5383a8b1d52 to your computer and use it in GitHub Desktop.
Save harshavardhana/0a1dc2939c7453c43287a5383a8b1d52 to your computer and use it in GitHub Desktop.
package main
import (
"bytes"
"fmt"
"io"
"log"
"os"
"github.com/cheggaaa/pb"
minio "github.com/minio/minio-go"
)
func main() {
s3Client, err := minio.New("play.minio.io:9000", "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", true)
if err != nil {
log.Fatalln(err)
}
var (
totalParts = 10000
partSize = int64(10 * 1024 * 1024)
i = 0
)
var srcs = make([]minio.SourceInfo, 10000)
progress := pb.New64(-1)
progress.Start()
var buf = make([]byte, partSize)
for i < totalParts {
length, rErr := io.ReadFull(os.Stdin, buf)
if rErr == io.EOF && i > 1 {
break
}
if rErr != nil && rErr != io.ErrUnexpectedEOF {
log.Fatalln(rErr)
}
s3Client.TraceOn(os.Stdout)
if _, err = s3Client.PutObject("testbucket", fmt.Sprintf("parts/%d", i), bytes.NewReader(buf[:length]), int64(len(buf[:length])),
minio.PutObjectOptions{
Progress: progress,
}); err != nil {
log.Fatalln(err)
}
// Source objects to concatenate.
srcs[i] = minio.NewSourceInfo("testbucket", fmt.Sprintf("parts/%d", i), nil)
i++
}
// Create destination info
dst, err := minio.NewDestinationInfo("testbucket", "final-object", nil, nil)
if err != nil {
log.Fatalln(err)
}
if err = s3Client.ComposeObject(dst, srcs[:i]); err != nil {
log.Fatalln(err)
}
objectsCh := make(chan string)
// Send object names that are needed to be removed to objectsCh
go func() {
defer close(objectsCh)
for j := 0; j < i+1; j++ {
objectsCh <- fmt.Sprintf("parts/%d", j)
}
}()
// Call RemoveObjects API
for e := range s3Client.RemoveObjects("my-bucketname", objectsCh) {
log.Fatalln("Failed to remove " + e.ObjectName + ", error: " + e.Err.Error())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment