Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
tanaka0325 committed Jul 20, 2020
1 parent a3839fb commit 9c60bc1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
5 changes: 3 additions & 2 deletions kadai2/tanaka0325/imgconv/cmd/imgconv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ func main() {
// convert
for _, path := range paths {
param := imgconv.ConvertParam{
File: imgconv.NewFile(path),
Path: path,
File: imgconv.NewFile(),
BeforeImage: imgconv.NewImage(*options.From),
AfterImage: imgconv.NewImage(*options.To),
FromExt: *options.From,
Expand All @@ -52,7 +53,7 @@ func main() {
onExit(err)
}
} else {
fmt.Printf("%[1]s.%[2]s => %[1]s.%[3]s\n", param.File.GetPath(), param.FromExt, param.ToExt)
fmt.Printf("%[1]s.%[2]s => %[1]s.%[3]s\n", path, param.FromExt, param.ToExt)
}
}
}
Expand Down
15 changes: 6 additions & 9 deletions kadai2/tanaka0325/imgconv/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@ import (
)

type OpenCreator interface {
Open() (io.ReadCloser, error)
Create() (io.WriteCloser, error)
GetPath() string
Open(string) (io.ReadCloser, error)
Create(string) (io.WriteCloser, error)
}

type File struct {
Path string
}

func (f *File) Open() (io.ReadCloser, error) { return os.Open(f.Path) }
func (f *File) Create() (io.WriteCloser, error) { return os.Create(f.Path) }
func (f *File) GetPath() string { return f.Path }
func (f *File) Open(n string) (io.ReadCloser, error) { return os.Open(n) }
func (f *File) Create(n string) (io.WriteCloser, error) { return os.Create(n) }

func NewFile(p string) *File {
return &File{Path: p}
func NewFile() *File {
return &File{}
}
5 changes: 3 additions & 2 deletions kadai2/tanaka0325/imgconv/imgconv.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package imgconv

type ConvertParam struct {
Path string
File OpenCreator
BeforeImage Decoder
AfterImage Encoder
Expand All @@ -11,7 +12,7 @@ type ConvertParam struct {

func Do(param ConvertParam) (err error) {
// open file
r, err := param.File.Open()
r, err := param.File.Open(param.Path + "." + param.FromExt)
if err != nil {
return
}
Expand All @@ -24,7 +25,7 @@ func Do(param ConvertParam) (err error) {
}

// create file
w, err := param.File.Create()
w, err := param.File.Create(param.Path + "." + param.ToExt)
if err != nil {
return err
}
Expand Down

0 comments on commit 9c60bc1

Please sign in to comment.