Пример #1
0
// UnPack get tar.gz bytes and returns path width bytes map
func UnPack(bs []byte) (map[string][]byte, error) {
	pathBytesMap := make(map[string][]byte)
	br := bytes.NewReader(bs)

	gr, err := gzip.NewReader(br)
	if err != nil {
		return nil, err
	}
	defer gr.Close()

	tr := tar.NewReader(gr)

	for {
		h, err := tr.Next()
		if err == io.EOF {
			break
		}
		if err != nil {
			return nil, err
		}

		path := h.Name
		bs := stringutils.ReaderToBytes(tr)
		pathBytesMap[path] = bs
	}

	return pathBytesMap, nil
}
Пример #2
0
Файл: s3.go Проект: get3w/get3w
// Read return resource content
func (service Service) Read(key string) ([]byte, error) {
	if key == "" {
		return nil, fmt.Errorf("key must be a nonempty string")
	}

	params := &s3.GetObjectInput{
		Bucket: aws.String(service.bucketSource), // Required
		Key:    aws.String(key),                  // Required
	}
	resp, err := service.instance.GetObject(params)
	if err != nil {
		return nil, err
	}

	return stringutils.ReaderToBytes(resp.Body), nil
}