func (s *Service) HeadObject(o *fs.Object) (code int, err error) { url := s.Host + o.EntryURI resp, err := s.Conn.Post("HEAD", url) if err != nil { return } defer resp.Body.Close() code = resp.StatusCode if code/100 == 2 { o.Type = resp.Header.Get("Content-Type") o.ETag = resp.Header.Get("ETag") o.Size, err = strconv.ParseInt(resp.Header.Get("Content-Length"), 10, 64) if err != nil { o.Size = 0 } o.Mtime = resp.Header.Get("Last-Modified") if o.Meta == nil { o.Meta = make(map[string]string) } for k, v := range resp.Header { prefix := "x-oss-meta-" if strings.HasPrefix(k, prefix) == false { continue } o.Meta[strings.TrimLeft(k, prefix)] = v[0] } } return }
func (s *Service) GetObject(o *fs.Object) (code int, err error) { url := s.Host + o.EntryURI resp, err := s.Conn.Post("GET", url) if err != nil { return } defer resp.Body.Close() code = resp.StatusCode if code/100 == 2 && resp.ContentLength != 0 { o.Size, err = io.Copy(o.Body, resp.Body) if err != nil { return } o.ETag = resp.Header.Get("ETag") o.Type = resp.Header.Get("Content-Type") o.Mtime = resp.Header.Get("Last-Modified") } return }