Update vendor github.com/cavaliercoder/grab

This commit is contained in:
Daniele Rondina
2020-11-19 00:56:59 +01:00
parent f9a7113ab9
commit 287098f101
14 changed files with 391 additions and 140 deletions

View File

@@ -1,9 +1,7 @@
package grab
import (
"context"
"fmt"
"hash"
"mime"
"net/http"
"os"
@@ -36,22 +34,26 @@ func mkdirp(path string) error {
if !os.IsNotExist(err) {
return fmt.Errorf("error checking destination directory: %v", err)
}
if err := os.MkdirAll(dir, 0755); err != nil {
if err := os.MkdirAll(dir, 0777); err != nil {
return fmt.Errorf("error creating destination directory: %v", err)
}
} else if !fi.IsDir() {
panic("destination path is not directory")
panic("grab: developer error: destination path is not directory")
}
return nil
}
// guessFilename returns a filename for the given http.Response. If none can be
// determined ErrNoFilename is returned.
//
// TODO: NoStore operations should not require a filename
func guessFilename(resp *http.Response) (string, error) {
filename := resp.Request.URL.Path
if cd := resp.Header.Get("Content-Disposition"); cd != "" {
if _, params, err := mime.ParseMediaType(cd); err == nil {
filename = params["filename"]
if val, ok := params["filename"]; ok {
filename = val
} // else filename directive is missing.. fallback to URL.Path
}
}
@@ -67,23 +69,3 @@ func guessFilename(resp *http.Response) (string, error) {
return filename, nil
}
// checksum returns a hash of the given file, using the given hash algorithm.
func checksum(ctx context.Context, filename string, h hash.Hash) (b []byte, err error) {
var f *os.File
f, err = os.Open(filename)
if err != nil {
return
}
defer func() {
err = f.Close()
}()
t := newTransfer(ctx, nil, h, f, nil)
if _, err = t.copy(); err != nil {
return
}
b = h.Sum(nil)
return
}