Skip to content

Instantly share code, notes, and snippets.

@suzusuzu
Last active December 18, 2016 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suzusuzu/84a21cb87b9ecb0bbb46e85082acc1bc to your computer and use it in GitHub Desktop.
Save suzusuzu/84a21cb87b9ecb0bbb46e85082acc1bc to your computer and use it in GitHub Desktop.
ungif
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