BIG rewrite stream info

This commit is contained in:
Alex X
2024-06-15 16:46:03 +03:00
parent ecfe802065
commit 96504e2fb0
88 changed files with 1043 additions and 854 deletions
+56
View File
@@ -0,0 +1,56 @@
package mpjpeg
import (
"bufio"
"errors"
"io"
"net/http"
"net/textproto"
"strconv"
"strings"
)
func Next(rd *bufio.Reader) (http.Header, []byte, error) {
for {
// search next boundary and skip empty lines
s, err := rd.ReadString('\n')
if err != nil {
return nil, nil, err
}
if strings.HasPrefix(s, "--") {
break
}
if s == "\r\n" {
continue
}
return nil, nil, errors.New("multipart: wrong boundary: " + s)
}
tp := textproto.NewReader(rd)
header, err := tp.ReadMIMEHeader()
if err != nil {
return nil, nil, err
}
s := header.Get("Content-Length")
if s == "" {
return nil, nil, errors.New("multipart: no content length")
}
size, err := strconv.Atoi(s)
if err != nil {
return nil, nil, err
}
buf := make([]byte, size)
if _, err = io.ReadFull(rd, buf); err != nil {
return nil, nil, err
}
_, _ = rd.Discard(2) // skip "\r\n"
return http.Header(header), buf, nil
}