Modify remarks

This commit is contained in:
LinkLeong 2023-03-21 02:11:35 +00:00
commit 8f670917c6
2 changed files with 4 additions and 29 deletions

View File

@ -598,19 +598,6 @@ func NameAccumulation(name string, dir string) string {
} }
} }
// / 解析多个文件上传中,每个具体的文件的信息
// type FileHeader struct {
// ContentDisposition string
// Name string
// FileName string
// ///< 文件名
// ContentType string
// ContentLength int64
// }
// / 解析描述文件信息的头部
// / @return FileHeader 文件名等信息的结构体
// / @return bool 解析成功还是失败
func ParseFileHeader(h []byte, boundary []byte) (map[string]string, bool) { func ParseFileHeader(h []byte, boundary []byte) (map[string]string, bool) {
arr := bytes.Split(h, boundary) arr := bytes.Split(h, boundary)
//var out_header FileHeader //var out_header FileHeader
@ -677,10 +664,6 @@ func ParseFileHeader(h []byte, boundary []byte) (map[string]string, bool) {
return result, true return result, true
} }
// / 从流中一直读到文件的末位
// / @return []byte 没有写到文件且又属于下一个文件的数据
// / @return bool 是否已经读到流的末位了
// / @return error 是否发生错误
func ReadToBoundary(boundary []byte, stream io.ReadCloser, target io.WriteCloser) ([]byte, bool, error) { func ReadToBoundary(boundary []byte, stream io.ReadCloser, target io.WriteCloser) ([]byte, bool, error) {
read_data := make([]byte, 1024*8) read_data := make([]byte, 1024*8)
read_data_len := 0 read_data_len := 0
@ -695,15 +678,15 @@ func ReadToBoundary(boundary []byte, stream io.ReadCloser, target io.WriteCloser
} }
reach_end = true reach_end = true
} }
//todo: 下面这一句很蠢,值得优化
copy(read_data[read_data_len:], buf[:read_len]) //追加到另一块buffer仅仅只是为了搜索方便 copy(read_data[read_data_len:], buf[:read_len])
read_data_len += read_len read_data_len += read_len
if read_data_len < b_len+4 { if read_data_len < b_len+4 {
continue continue
} }
loc := bytes.Index(read_data[:read_data_len], boundary) loc := bytes.Index(read_data[:read_data_len], boundary)
if loc >= 0 { if loc >= 0 {
//找到了结束位置
target.Write(read_data[:loc-4]) target.Write(read_data[:loc-4])
return read_data[loc:read_data_len], reach_end, nil return read_data[loc:read_data_len], reach_end, nil
} }
@ -715,14 +698,6 @@ func ReadToBoundary(boundary []byte, stream io.ReadCloser, target io.WriteCloser
return nil, reach_end, nil return nil, reach_end, nil
} }
// / 解析表单的头部
// / @param read_data 已经从流中读到的数据
// / @param read_total 已经从流中读到的数据长度
// / @param boundary 表单的分割字符串
// / @param stream 输入流
// / @return FileHeader 文件名等信息头
// /[]byte 已经从流中读到的部分
// /error 是否发生错误
func ParseFromHead(read_data []byte, read_total int, boundary []byte, stream io.ReadCloser) (map[string]string, []byte, error) { func ParseFromHead(read_data []byte, read_total int, boundary []byte, stream io.ReadCloser) (map[string]string, []byte, error) {
buf := make([]byte, 1024*8) buf := make([]byte, 1024*8)

View File

@ -651,7 +651,7 @@ func PostFileOctet(c *gin.Context) {
} }
f.Write(file_data) f.Write(file_data)
file_data = nil file_data = nil
//需要反复搜索boundary
temp_data, reach_end, err := file.ReadToBoundary(boundary, c.Request.Body, f) temp_data, reach_end, err := file.ReadToBoundary(boundary, c.Request.Body, f)
f.Close() f.Close()
if err != nil { if err != nil {