Example #1
0
File: targz.go Project: get3w/get3w
// 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
}
Example #2
0
File: s3.go Project: 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
}