s3zip

package module
v0.0.0-...-421317a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2022 License: MIT Imports: 10 Imported by: 0

README

s3zip

Package s3zip provides support for compressing AWS S3 objects.

It's a Proof of Concept project that hasn't been used in production.

Usage

package main

import (
	"context"
	"log"

	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/stind/s3zip"
)

func main() {
	sess := session.Must(session.NewSession())
	z := s3zip.New(sess, s3zip.WithConcurrency(10))
	ctx := context.Background()

	// Where to upload the zip archive
	destination := s3Zip.Object{
		Bucket: "destination-bucket-name",
		Key:    "destination-archive-name.zip",
	}

	resources := []s3zip.Resource{
		{
			FileName: "foo.txt",
			Object: s3zip.Object{
				Bucket: "source-bucket-name",
				Key:    "key/of/source-file-name.txt",
			},
		},
		{
			FileName: "bar/baz.txt",
			Object: s3zip.Object{
				Bucket: "source-bucket-name",
				Key:    "other/key/of/source-file-name.txt",
			},
		},
	}

	err := z.Do(ctx, destination, resources...)
	if err != nil {
		log.Fatal(err)
	}
}

Documentation

Overview

Package s3zip provides support for compressing AWS S3 objects.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithConcurrency

func WithConcurrency(c int) configOption

Types

type Object

type Object struct {
	Bucket string
	Key    string
}

Object describes an S3 object.

type Resource

type Resource struct {
	Object   Object
	FileName string // FileName is a desired path to the file in the archive.
	// contains filtered or unexported fields
}

Resource describes an S3 object that has to be packed into a zip archive.

type S3Zip

type S3Zip struct {
	// contains filtered or unexported fields
}

func New

func New(c awsclient.ConfigProvider, opts ...configOption) S3Zip

New creates a new S3Zip instance

func (S3Zip) Do

func (z S3Zip) Do(ctx context.Context, destObj Object, resources []Resource) error

Do downloads S3 objects, puts them into a zip archive and uploads it to the destination S3 object.

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL