From aa90abc3ff054b313bf5dbd2771170004dc2794e Mon Sep 17 00:00:00 2001 From: IllusionMan1212 Date: Sun, 23 May 2021 21:23:23 +0300 Subject: [PATCH] fix file perms, add gitignore and go.mod --- .gitignore | 1 + go.mod | 3 +++ main.go | 13 +++++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 go.mod diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..39b4a53 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +gifs/ \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..7f792fa --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/illusionman1212/gif-extractor-go + +go 1.16 diff --git a/main.go b/main.go index 29b7666..8368307 100644 --- a/main.go +++ b/main.go @@ -33,7 +33,7 @@ func (v Palette) UnmarshalBinary(data []byte) error { func main() { inputFile := os.Args[1] - file, err := os.OpenFile(inputFile, os.O_RDONLY, 0x755) + file, err := os.OpenFile(inputFile, os.O_RDONLY, os.FileMode(0755)) if err != nil { panic(err) } @@ -67,6 +67,15 @@ func main() { fmt.Printf("Global color table size: %v\n", GlobalColorTableSize) fmt.Printf("global color table entries: %v\n", GlobalColorTableEntries) + st, err := file.Stat() + if err != nil { + panic(err) + } + dirName := strings.Split(st.Name(), ".gif")[0] + + fmt.Printf("%v\n", dirName) + os.Mkdir(dirName, os.FileMode(0755)) + var palette Palette if GlobalColorTableFlag == 0 { // no global color table, use default one (???) @@ -176,7 +185,7 @@ func main() { panic(err) } - outFile, err := os.OpenFile(fmt.Sprintf("%s-raw.%v", file.Name(), i), os.O_CREATE|os.O_RDWR, 0755) + outFile, err := os.OpenFile(fmt.Sprintf("./%s/%s-raw.%v", dirName, st.Name(), i), os.O_CREATE|os.O_RDWR, os.FileMode(0755)) if err != nil { panic(err) }