func main() { if len(os.Args) < 3 { fmt.Fprintf(os.Stderr, "Usage: %s <infile> <outfile>\n", os.Args[0]) return } var in io.Reader = nil if os.Args[1] == "-" { in = os.Stdin } else if strings.HasPrefix(os.Args[1], "ws://") { url, err := url.Parse(os.Args[1]) checkError("Output url", err) origin := "http://localhost/" ws, err := websocket.Dial(url.String(), "", origin) checkError("WebSocket Dial", err) in = io.Reader(ws) } else { file, err := os.Open(os.Args[1]) checkError(fmt.Sprintf("can't open file %s", os.Args[1]), err) in = io.Reader(file) } file, err := os.Create(os.Args[2]) checkError(fmt.Sprintf("Failed to create file %s", os.Args[2]), err) out := io.WriteSeeker(file) buf := [4096]byte{} c := NewTestClient(out) parser := ebml.NewParser(ebml.GetListIDs(webm.IdTypes()), webm.UnknownSizeInfo(), ebml.NewElementParser(c, webm.IdTypes())) for { bytesRead, err := in.Read(buf[:]) if err != nil { parser.EndOfData() break } parser.Append(buf[0:bytesRead]) } }
func NewWebMParser() *ebml.Parser { c := newWebMClient() return ebml.NewParser(ebml.GetListIDs(webm.IdTypes()), webm.UnknownSizeInfo(), ebml.NewElementParser(c, webm.IdTypes())) }