Beispiel #1
0
func main() {
	// cae.Copy("test.zip", "zip/testdata/test.zip")
	fw, err := os.Create("hello.tar.gz")
	if err != nil {
		log.Fatal(err)
	}
	defer fw.Close()

	fr, err := os.Open("zip/testdata/gophercolor16x16.png")
	if err != nil {
		log.Fatal(err)
	}

	fi, err := fr.Stat()
	if err != nil {
		log.Fatal(err)
	}

	s := tz.NewStreamArachive(fw)
	if err = s.StreamReader("", fi, fr); err != nil {
		log.Fatal(err)
	}
	if err = s.Close(); err != nil {
		log.Fatal(err)
	}
}
Beispiel #2
0
func (c *Commit) CreateArchive(path string, archiveType ArchiveType) error {
	f, err := os.OpenFile(path, os.O_CREATE, 0644)
	if err == nil {
		f.Close()
	}

	f, err = os.OpenFile(path, os.O_WRONLY|os.O_TRUNC|os.O_EXCL, 0644)
	if err != nil {
		return err
	}
	defer f.Close()

	var streamer cae.Streamer
	switch archiveType {
	case AT_ZIP:
		streamer = zip.NewStreamArachive(f)
	case AT_TARGZ:
		streamer = tz.NewStreamArachive(f)
	}
	defer streamer.Close()

	return createArchive(&c.Tree, streamer)
}