GithubHelp home page GithubHelp logo

c4milo / gofetch Goto Github PK

View Code? Open in Web Editor NEW
27.0 4.0 2.0 10.26 MB

Go library for downloading content from internet, in parallel.

License: Mozilla Public License 2.0

Go 100.00%
parallel fetcher http gofetch etags downloader golang-library golang

gofetch's People

Contributors

c4milo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

junbinku devopsmi

gofetch's Issues

Check file integrity if a hash is provided

Here is a start:

func verify(f *os.File, checksumType, checksum string) (string, error) {
    // Makes sure file cursor is positioned at the beginning
    _, err := f.Seek(0, 0)
    if err != nil {
        return "", err
    }

    var hasher hash.Hash
    switch checksumType {
    case "md5":
        hasher = md5.New()
    case "sha1":
        hasher = sha1.New()
    case "sha256":
        hasher = sha256.New()
    case "sha512":
        hasher = sha512.New()
    default:
        return "", fmt.Errorf("crypto algorithm no supported: %s", checksumType)
    }
    _, err = io.Copy(hasher, f)
    if err != nil {
        return "", err
    }

    result := fmt.Sprintf("%x", hasher.Sum(nil))

    if result != checksum {
        return result, fmt.Errorf("checksum does not match\n found: %s\n expected: %s", result, checksum)
    }

    return result, nil
}

Resume test has a data race

FYI

$ go test -race -run Resume
==================
WARNING: DATA RACE
Read by goroutine 6:
  github.com/c4milo/gofetch.TestResume()
      /home/caleb/p/go/src/github.com/c4milo/gofetch/gofetch_test.go:129 +0x8db
  testing.tRunner()
      /home/caleb/apps/go/src/testing/testing.go:456 +0xdc

Previous write by goroutine 8:
  github.com/c4milo/gofetch.TestResume.func2()
      /home/caleb/p/go/src/github.com/c4milo/gofetch/gofetch_test.go:116 +0x15d

Goroutine 6 (running) created at:
  testing.RunTests()
      /home/caleb/apps/go/src/testing/testing.go:561 +0xaa3
  testing.(*M).Run()
      /home/caleb/apps/go/src/testing/testing.go:494 +0xe4
  main.main()
      github.com/c4milo/gofetch/_test/_testmain.go:58 +0x20f

Goroutine 8 (finished) created at:
  github.com/c4milo/gofetch.TestResume()
      /home/caleb/p/go/src/github.com/c4milo/gofetch/gofetch_test.go:118 +0x70f
  testing.tRunner()
      /home/caleb/apps/go/src/testing/testing.go:456 +0xdc
==================
PASS
Found 1 data race(s)
exit status 66
FAIL    github.com/c4milo/gofetch       1.126s

Add ETag support

We should avoid fetching a file if it was already fetched and its ETag matches with the previous download. I think we can enable ETag support by default and expose a configuration option to disable it, forcing downloads.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.