Read some bytes

This commit is contained in:
Rob Watson 2021-01-25 09:03:24 +01:00
parent 08b288d6a7
commit 67be7684dc
3 changed files with 47 additions and 0 deletions

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module git.netflux.io/rob/avframes
go 1.15

1
internal/mpeg/mpeg.go Normal file
View File

@ -0,0 +1 @@
package mpeg

43
main.go Normal file
View File

@ -0,0 +1,43 @@
package main
import (
"bufio"
"fmt"
"io"
"log"
"os"
)
const fname = "/home/rob/Desktop/example.mp3"
const syncHeader1 = 0xFF
const syncHeader2 = 0xFE
func main() {
f, err := os.Open(fname)
if err != nil {
log.Fatal(err)
}
bufreader := bufio.NewReader(f)
buf := make([]byte, 4)
var i int
for {
_, err := io.ReadFull(bufreader, buf)
if err != nil {
log.Fatal(err)
}
if parseBytes(buf) {
fmt.Printf("Got possible header %X at %d\n", buf, i)
}
i++
bufreader.UnreadByte()
}
}
func parseBytes(buf []byte) bool {
return buf[0]&syncHeader1 == syncHeader1 || buf[0]&syncHeader2 == syncHeader2
}