upload

package
v0.0.0-...-a6dfa66 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2024 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Zip = compressor{
		ContentType: "application/zip",
		Ext:         ".zip",
		Compress: func(ctx context.Context, dst io.Writer, root string) (err error) {
			z := zipper.New()
			z.ProgressReporter, err = zipper.NewProgressBarReporter(ctx, root, nil)
			if err == nil {
				err = z.CompressDir(ctx, root, dst, false)
			}
			return
		},
	}
	XZ = compressor{
		ContentType: "application/x-xz",
		Ext:         ".tar.xz",
		Compress: func(ctx context.Context, dst io.Writer, root string) error {
			base := filepath.Base(root)

			_, size, err := zipper.CountDirContents(ctx, root)
			if err != nil {
				return err
			}

			bar := internal.DefaultBytes(size, "compressing")

			xzw, err := xz.NewWriter(dst)
			if err != nil {
				return err
			}

			tw := tar.NewWriter(xzw)

			if err = zipper.WalkRegularFiles(ctx, root, func(path string, d fs.DirEntry) error {
				fi, err := d.Info()
				if err != nil {
					return err
				}

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

				if path, err = filepath.Rel(root, path); err != nil {
					return err
				}

				if err = tw.WriteHeader(&tar.Header{
					Name: filepath.Join(base, path),
					Size: fi.Size(),
					Mode: 0600,
				}); err == nil {
					err = internal.CopyWithContext(ctx, io.MultiWriter(tw, bar), src)
				}

				return err
			}); err != nil {
				return err
			}

			if err = tw.Close(); err == nil {
				err = xzw.Close()
			}

			return err
		},
	}
)

Functions

This section is empty.

Types

type Command

type Command struct {
	Bucket              string  `short:"b" long:"bucket" description:"name of the S3 bucket containing the files" required:"true"`
	Prefix              string  `short:"k" long:"key-prefix" description:"key prefix to apply to all S3 operations"`
	ExpectedBucketOwner *string `long:"expected-bucket-owner" description:"optional ExpectedBucketOwner field to apply to all S3 operations"`
	Delete              bool    `` /* 208-byte string literal not displayed */
	XZ                  bool    `long:"xz" description:"if given, local directories will be tar-ed and compressed instead of using zip by default"`
	MaxConcurrency      int     `` /* 137-byte string literal not displayed */
	Args                struct {
		Files []flags.Filename `` /* 222-byte string literal not displayed */
	} `positional-args:"yes"`
	// contains filtered or unexported fields
}

func (*Command) Execute

func (c *Command) Execute(args []string) error

Jump to

Keyboard shortcuts

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