|
| 1 | +Pipe Dream |
| 2 | +========== |
| 3 | + |
| 4 | +<p> |
| 5 | + <a href="https://github.com/meowgorithm/pipedream/releases"><img src="https://img.shields.io/github/release/meowgorithm/pipedream.svg" alt="Latest Release"></a> |
| 6 | + <a href="https://pkg.go.dev/github.com/meowgorithm/pipedream?tab=doc"><img src="https://godoc.org/github.com/golang/gddo?status.svg" alt="GoDoc"></a> |
| 7 | + <a href="https://github.com/meowgorithm/pipedream/actions"><img src="https://github.com/meowgorithm/pipedream/workflows/build/badge.svg" alt="Build Status"></a> |
| 8 | +</p> |
| 9 | + |
| 10 | +Easy multipart uploads for Amazon S3, DigitalOcean Spaces and S3-compatible |
| 11 | +services. Available as a CLI and Go library. |
| 12 | + |
| 13 | +## CLI |
| 14 | + |
| 15 | +### Install It |
| 16 | + |
| 17 | +Download a build from the [releases][releases] page. macOS, Linux and Windows builds are available for various architectures. |
| 18 | + |
| 19 | +macOS users can also use Homebrew: |
| 20 | + |
| 21 | +``` |
| 22 | +brew install meowgorithm/homebrew-tap/pipedream |
| 23 | +``` |
| 24 | + |
| 25 | +Or you can just use `go get`: |
| 26 | + |
| 27 | +```bash |
| 28 | +go get github.com/meowgorithm/pipedream/pipedream |
| 29 | +``` |
| 30 | + |
| 31 | +[releases]: https://github.com/meowgorithm/pipedream/releases |
| 32 | + |
| 33 | +### Usage |
| 34 | + |
| 35 | +```bash |
| 36 | +# Set your secrets, region and endpoint in the environment |
| 37 | +export ACCESS_KEY="..." |
| 38 | +export SECRET_KEY="..." |
| 39 | +export ENDPOINT="sfo2.digitaloceanspaces.com" # for AWS set REGION |
| 40 | + |
| 41 | +# Pipe in data or redirect in a file |
| 42 | +pipedream --bucket images --path pets/puppy.jpg < puppy.jpg |
| 43 | + |
| 44 | +# Get fancy |
| 45 | +export now=$(date +"%Y-%m-%d_%H:%M:%S_%Z") |
| 46 | +cat /data/dump.rdb | gzip | pipedream -bucket backups -path dump-$(now).rdb.gz |
| 47 | + |
| 48 | +# For more info |
| 49 | +pipedream -h |
| 50 | +``` |
| 51 | + |
| 52 | +## Library |
| 53 | + |
| 54 | +The library uses an event based model, sending events through a channel. |
| 55 | + |
| 56 | +```go |
| 57 | +import "github.com/meowgorithm/pipedream" |
| 58 | + |
| 59 | +// Create a new multipart upload object |
| 60 | +m := pipedream.MultipartUpload{ |
| 61 | + AccessKey: os.Getenv("ACCESS_KEY"), |
| 62 | + SecretKey: os.Getenv("SECRET_KEY"), |
| 63 | + Endpoint: "sfo2.digitaloceanspaces.com", // you could use Region for AWS |
| 64 | + Bucket: "my-fave-bucket", |
| 65 | +} |
| 66 | + |
| 67 | +// Get an io.Reader, like an *os.File or os.Stdout |
| 68 | +f, err := os.Open("big-redis-dump.rdb") |
| 69 | +if err != nil { |
| 70 | + fmt.Printf("Rats: %v\n", err) |
| 71 | + os.Exit(1) |
| 72 | +} |
| 73 | +defer f.Close() |
| 74 | + |
| 75 | +// Send up the data. Pipdream returns a channel where you can listen for events |
| 76 | +ch := m.Send(f, "backups/dump.rdb") |
| 77 | +done := make(chan struct{}) |
| 78 | + |
| 79 | +// Listen for activity. For more detailed reporting, see the docs |
| 80 | +go func() { |
| 81 | + for { |
| 82 | + e := <-ch |
| 83 | + switch e.(type) { |
| 84 | + case pipedream.Complete: |
| 85 | + fmt.Println("It worked!") |
| 86 | + close(done) |
| 87 | + return |
| 88 | + case pipedream.Error: |
| 89 | + fmt.Println("Rats, it didn't work.") |
| 90 | + close(done) |
| 91 | + return |
| 92 | + } |
| 93 | + } |
| 94 | +}() |
| 95 | + |
| 96 | +<-done |
| 97 | +``` |
| 98 | + |
| 99 | +[Full source][example] of this example. For an example with more detailed |
| 100 | +reporting, see the source code in the [CLI][cli]. |
| 101 | + |
| 102 | +[example]: https://github.com/meowgorithm/pipedream/blob/master/example/main.go |
| 103 | +[cli]: https://github.com/meowgorithm/pipedream/tree/master/pipedream |
| 104 | + |
| 105 | +## Awknowledgements |
| 106 | + |
| 107 | +Thanks to to Apoorva Manjunath‘s [S3 multipart upload example](https://github.com/apoorvam/aws-s3-multipart-upload) |
| 108 | +for the S3 implementation details. |
| 109 | + |
| 110 | +## License |
| 111 | + |
| 112 | +[MIT](https://github.com/meowgorithm/pipedream/raw/master/LICENSE) |
0 commit comments