Beispiel #1
0
func (backend *S3Backend) Enumerate(blobs chan<- string) error {
	defer close(blobs)
	f, err := s3util.NewFile(backend.bucket(""), nil)
	if err != nil {
		return err
	}
	var infos []os.FileInfo
	for {
		infos, err = f.Readdir(0)
		if err == io.EOF {
			break
		} else if err != nil {
			return err
		}
		for _, info := range infos {
			sf, err := s3util.NewFile(backend.bucket(info.Name()+"/"), nil)
			if err != nil {
				return err
			}
			var subinfos []os.FileInfo
			for {
				subinfos, err = sf.Readdir(0)
				if err == io.EOF {
					break
				} else if err != nil {
					return err
				}
				for _, subinfo := range subinfos {
					blobs <- subinfo.Name()[3:] //subinfo.Sys().(*s3util.Stat).Key
				}
			}
		}
	}
	return nil
}
Beispiel #2
0
func ExampleReaddir() {
	s3util.DefaultConfig.AccessKey = os.Getenv("S3_ACCESS_KEY")
	s3util.DefaultConfig.SecretKey = os.Getenv("S3_SECRET_KEY")
	f, err := s3util.NewFile("https://examle.s3.amazonaws.com/foo", nil)
	if err != nil {
		panic(err)
	}
	var infos []os.FileInfo
	for {
		infos, err = f.Readdir(0)
		if err == io.EOF {
			break
		} else if err != nil {
			panic(err)
		}
		for i, info := range infos {
			c := info.Sys().(*s3util.Stat)
			var etag string
			if c != nil {
				etag = c.ETag
			}
			fmt.Printf("%d: %v, %s\n", i, info, etag)
		}
	}
}