Last active
December 18, 2016 01:23
-
-
Save suzusuzu/84a21cb87b9ecb0bbb46e85082acc1bc to your computer and use it in GitHub Desktop.
ungif
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
) | |
func main() { | |
if len(os.Args) != 3 { | |
fmt.Println("need 2 args (ex: gif input.gif output") | |
os.Exit(-1) | |
} | |
inputFileInfo, err := os.Stat(os.Args[1]) | |
if err != nil { | |
fmt.Println("input file not found") | |
os.Exit(-1) | |
} | |
inputFile, err := os.Open(os.Args[1]) | |
defer inputFile.Close() | |
if err != nil { | |
fmt.Println("input file error") | |
os.Exit(-1) | |
} | |
outputFile, err := os.Create(os.Args[2]) | |
defer outputFile.Close() | |
if err != nil { | |
fmt.Println("input file error") | |
os.Exit(-1) | |
} | |
extractDataWrite(inputFile, inputFileInfo.Size(), outputFile) | |
} | |
func extractDataWrite(inputFile *os.File, inputFileSize int64, outputFile *os.File) { | |
inputFile.Seek(24, 0) | |
b255 := make([]byte, 256) | |
for { | |
inputFile.Read(b255) | |
if b255[0] != uint8(255) { | |
break | |
} | |
outputFile.Write(b255[1:]) | |
} | |
outputFile.Write(b255[1 : (inputFileSize-26)%256]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment