func (fs *S3FS) OpenRange(name string, rangeHeader string) (f vfs.ReadSeekCloser, err error) { cfg := fs.config if rangeHeader != "" { tmp := *cfg cfg = &tmp var existingTransport http.RoundTripper if cfg.Client != nil { existingTransport = cfg.Client.Transport } cfg.Client = &http.Client{Transport: rangeTransport{RoundTripper: existingTransport, rangeVal: rangeHeader}} } rdr, err := s3util.Open(fs.url(name), cfg) if err != nil { return nil, &os.PathError{Op: "open", Path: fs.url(name), Err: err} } b, err := ioutil.ReadAll(rdr) if err != nil { return nil, err } defer func() { err2 := rdr.Close() if err == nil { err = err2 } }() return nopCloser{bytes.NewReader(b)}, nil }
func (c *Cache) Get(key string) (resp []byte, ok bool) { rdr, err := s3util.Open(c.url(key), &c.Config) if err != nil { return []byte{}, false } defer rdr.Close() if c.Gzip { rdr, err = gzip.NewReader(rdr) if err != nil { return nil, false } defer rdr.Close() } resp, err = ioutil.ReadAll(rdr) if err != nil { log.Printf("s3cache.Get failed: %s", err) } return resp, err == nil }