tarwriter

package module
v0.0.0-...-9580712 Latest Latest
Warning

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

Go to latest
Published: May 18, 2019 License: MIT Imports: 8 Imported by: 0

README

TarWriter

This package was created send files to a docker container via Official Go SDK for Docker more easily.

Usage with Official Go SDK for Docker

var tarArchive bytes.Buffer
tarWriter := tarwriter.NewTarWriter(&tarArchive)

err := tarWriter.AddFolder("somedirectory", tarwriter.AddFolderOptions{IncludeRootFolder: true})
if err != nil{
	return err
}

err := tarWriter.AddFile("somefile.txt", tarwriter.AddFileOptions{})
if err != nil{
	return err
}

err := tarWriter.AddContentFile("someotherfile.txt", []byte("content"), tarwriter.AddFileOptions{})
if err != nil{
	return err
}

tarWriter.Close()

err = cli.CopyToContainer(ctx,
    createResp.ID,
    "/home/user",
    &tarArchive,
    types.CopyToContainerOptions{AllowOverwriteDirWithFile: true},
)
if err != nil {
    return err
}

Usage with HTTP Request

var tarArchive bytes.Buffer
tarWriter := tarwriter.NewTarWriter(&tarArchive)

err := tarWriter.AddFolder("somedirectory", tarwriter.AddFolderOptions{IncludeRootFolder: true})
if err != nil{
	return err
}

err := tarWriter.AddFile("somefile.txt", tarwriter.AddFileOptions{})
if err != nil{
	return err
}

err := tarWriter.AddContentFile("someotherfile.txt", []byte("content"), tarwriter.AddFileOptions{})
if err != nil{
	return err
}

tarWriter.Close()

req, err := http.NewRequest(http.MethodPut, "https://someurl.org/archive.tar", &tarArchive)
if err != nil{
	return err
}

Usage with Files

var tarArchive bytes.Buffer
tarWriter := tarwriter.NewTarWriter(&tarArchive)

err := tarWriter.AddFolder("somedirectory", tarwriter.AddFolderOptions{IncludeRootFolder: true})
if err != nil{
	return err
}

err := tarWriter.AddFile("somefile.txt", tarwriter.AddFileOptions{})
if err != nil{
	return err
}

err := tarWriter.AddContentFile("someotherfile.txt", []byte("content"), tarwriter.AddFileOptions{})
if err != nil{
	return err
}

tarWriter.Close()

file, err := os.Create("archive.tar")
if err != nil{
	return err
}
defer file.Close()

_, err := io.Copy(file, &tarArchive)
if err != nil{
	return err
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddFileOptions

type AddFileOptions struct {
	InternalPath         string
	ForceExecutableFlags bool
}

type AddFolderOptions

type AddFolderOptions struct {
	InternalPath         string
	ForceExecutableFlags bool
	NonRecursive         bool
	IncludeRootFolder    bool
}

type TarWriter

type TarWriter struct {
	tar.Writer
}

func NewTarWriter

func NewTarWriter(w io.Writer) *TarWriter

func (*TarWriter) AddContentFile

func (tf *TarWriter) AddContentFile(filename string, content []byte, options AddFileOptions) error

func (*TarWriter) AddEmptyFolder

func (tf *TarWriter) AddEmptyFolder(folderPath, internalPath string) error

func (*TarWriter) AddFile

func (tf *TarWriter) AddFile(filePath string, options AddFileOptions) error

func (*TarWriter) AddFiles

func (tf *TarWriter) AddFiles(filePaths []string, options AddFileOptions) error

func (*TarWriter) AddFolder

func (tf *TarWriter) AddFolder(folderPath string, options AddFolderOptions) error

func (*TarWriter) AddFolders

func (tf *TarWriter) AddFolders(folderPaths []string, options AddFolderOptions) error

Jump to

Keyboard shortcuts

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