diff options
| author | Mitchell Riedstra <mitch@riedstra.dev> | 2021-08-04 20:06:07 -0400 |
|---|---|---|
| committer | Mitchell Riedstra <mitch@riedstra.dev> | 2021-08-04 20:06:07 -0400 |
| commit | 742938b00222c7ad57ad11eb24850d9202c2503d (patch) | |
| tree | e0d1d033027d5dd553c213ed41bb8ae201d6a285 /steam/http.go | |
| parent | a5a49ff08056a67cc57435f219aa157342a0d9a0 (diff) | |
| download | steam-export-742938b00222c7ad57ad11eb24850d9202c2503d.tar.gz steam-export-742938b00222c7ad57ad11eb24850d9202c2503d.tar.xz | |
Pretty large structural changes. Non-building development snapshot
Diffstat (limited to 'steam/http.go')
| -rw-r--r-- | steam/http.go | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/steam/http.go b/steam/http.go new file mode 100644 index 0000000..df756e4 --- /dev/null +++ b/steam/http.go @@ -0,0 +1,61 @@ +package steam + +import ( + "fmt" + "net/http" + "os" + "strconv" +) + +// ExtractFile is a wrapper around Extract that handles an HTTP endpoint. +// this spawns an "extractFile" on the library. Status will be updated there +// as this goes along. Non fatal and fatal errors will be populated there +func (l *Library) ExtractFile(fn string) (*Game, error) { + g := &Game{} + j := newJob("extractFile", g) + defer j.done() + + l.status.addJob(j) + + fi, err := os.Stat(fn) + if err != nil { + j.addError(err) + return g, err + } + j.setSize(fi.Size()) + + fh, err := os.Open(fn) + if err != nil { + j.addError(err) + return g, err + } + + return l.extractUpdate(j, g, fh) +} + +// ExtractHTTP is a wrapper around Extract that handles an HTTP endpoint. +// this spawns an "extractHTTP" on the library. Status will be updated there +// as this goes along. Non fatal and fatal errors will be populated there +func (l *Library) ExtractHTTP(url string) (*Game, error) { + g := &Game{} + j := newJob("extractHTTP", g) + defer j.done() + + l.status.addJob(j) + + resp, err := http.Get(url) + if err != nil { + j.addError(err) + return g, err + } + + estSize, err := strconv.ParseInt(resp.Header.Get("Estimated-size"), 10, 64) + if err != nil { + j.addError(err) + return g, fmt.Errorf("Failed to convert estimated size header: %w", err) + } + + j.setSize(estSize) + + return l.extractUpdate(j, g, resp.Body) +} |
