Skip to content

Commit

Permalink
refactor: add archiver constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
ybirader committed Aug 10, 2023
1 parent a48c565 commit aab3217
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 7 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ import (

type Archiver struct {
Dest *os.File
W *zip.Writer
w *zip.Writer
}

func NewArchiver(archive *os.File) *Archiver {
return &Archiver{Dest: archive, w: zip.NewWriter(archive)}
}

func (a *Archiver) Archive() {
a.W.Create("hello.txt")
a.W.Close()
a.w.Create("hello.txt")
a.w.Close()
}

func main() {
Expand Down
3 changes: 1 addition & 2 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ func TestArchive(t *testing.T) {
archive, cleanup := createTempArchive(t, "testdata/archive.zip")
defer cleanup()

writer := zip.NewWriter(archive)
archiver := Archiver{Dest: archive, W: writer}
archiver := NewArchiver(archive)
archiver.Archive()

archiveReader, err := zip.OpenReader(archive.Name())
Expand Down

0 comments on commit aab3217

Please sign in to comment.