Skip to content

Commit

Permalink
refactoring: Session.dumpState
Browse files Browse the repository at this point in the history
  • Loading branch information
vbauerster committed Mar 15, 2024
1 parent 28f8efb commit c7e92b4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
11 changes: 1 addition & 10 deletions getparty.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"crypto/tls"
"crypto/x509"
"encoding/json"
"fmt"
"io"
"log"
Expand Down Expand Up @@ -330,7 +329,7 @@ func (cmd Cmd) makeSessionHandler(session *Session, progress *mpb.Progress) func
session.Elapsed += time.Since(start)
session.dropSkipped()
name := session.OutputFileName + ".json"
err := cmd.dumpState(name, session)
err := session.dumpState(name)
progress.Wait()
fmt.Fprintln(cmd.Out)
if err != nil {
Expand Down Expand Up @@ -702,14 +701,6 @@ func (cmd Cmd) overwriteIfConfirmed(name string) error {
return nil
}

func (cmd Cmd) dumpState(name string, session *Session) error {
f, err := os.Create(name)
if err != nil {
return err
}
return eitherError(json.NewEncoder(f).Encode(session), f.Close())
}

func eitherError(errors ...error) error {
for _, err := range errors {
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ func (s *Session) loadState(name string) error {
return eitherError(json.NewDecoder(f).Decode(s), f.Close())
}

func (s *Session) dumpState(name string) error {
f, err := os.Create(name)
if err != nil {
return err
}
return eitherError(json.NewEncoder(f).Encode(s), f.Close())
}

func (s Session) totalWritten() int64 {
var total int64
for _, p := range s.Parts {
Expand Down

0 comments on commit c7e92b4

Please sign in to comment.