-
-
Save phuysmans/37b01318823904847a01d019cb154b1a to your computer and use it in GitHub Desktop.
write some bytes to a file in golang
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" | |
"encoding/binary" | |
) | |
func WritePPMHeader(outf *os.File) { | |
fheader := []byte("P6\n") | |
binary.Write(outf,binary.LittleEndian,fheader) | |
fheader2 := []byte("640 480\n") | |
binary.Write(outf,binary.LittleEndian,fheader2) | |
fheader3 := []byte("255\n") | |
binary.Write(outf,binary.LittleEndian,fheader3) | |
} | |
func main() { | |
outf,_ := os.Create("junk.bin") | |
WritePPMHeader(outf) | |
for i :=0;i<50;i++ { | |
var ii uint8 = uint8(i) | |
err := binary.Write(outf, binary.LittleEndian, ii) | |
if err != nil { | |
fmt.Println("err!",err) | |
} | |
} | |
outf.Close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment