fn read_stream(
        payload: &mut PayloadBuffer,
        boundary: &str,
    ) -> Poll<Option<Result<Bytes, MultipartError>>> {
        let mut pos = 0;

        let len = payload.buf.len();
        if len == 0 {
            return if payload.eof {
                Poll::Ready(Some(Err(MultipartError::Incomplete)))
            } else {
                Poll::Pending
            };
        }

        // check boundary
        if len > 4 && payload.buf[0] == b'\r' {
            let b_len = if &payload.buf[..2] == b"\r\n" && &payload.buf[2..4] == b"--" {
                Some(4)
            } else if &payload.buf[1..3] == b"--" {
                Some(3)
            } else {
                None
            };

            if let Some(b_len) = b_len {
                let b_size = boundary.len() + b_len;
                if len < b_size {
                    return Poll::Pending;
                } else if &payload.buf[b_len..b_size] == boundary.as_bytes() {
                    // found boundary
                    return Poll::Ready(None);
                }
            }
        }

        loop {
            return if let Some(idx) = twoway::find_bytes(&payload.buf[pos..], b"\r") {
                let cur = pos + idx;

                // check if we have enough data for boundary detection
                if cur + 4 > len {
                    if cur > 0 {
                        Poll::Ready(Some(Ok(payload.buf.split_to(cur).freeze())))
                    } else {
                        Poll::Pending
                    }
                } else {
                    // check boundary
                    if (&payload.buf[cur..cur + 2] == b"\r\n"
                        && &payload.buf[cur + 2..cur + 4] == b"--")
                        || (&payload.buf[cur..=cur] == b"\r"
                            && &payload.buf[cur + 1..cur + 3] == b"--")
                    {
                        if cur != 0 {
                            // return buffer
                            Poll::Ready(Some(Ok(payload.buf.split_to(cur).freeze())))
                        } else {
                            pos = cur + 1;
                            continue;
                        }
                    } else {
                        // not boundary
                        pos = cur + 1;
                        continue;
                    }
                }
            } else {
                Poll::Ready(Some(Ok(payload.buf.split().freeze())))
            };
        }
    }
/// Reads content chunk of body part with unknown length.
/// The `Content-Length` header for body part is not necessary.
Reads content chunk of body part with unknown length.
The `Content-Length` header for body part is not necessary.
Reads content chunk of body part with unknown length . The ` Content - Length ` header for body part is not necessary .
fn read_stream(
        payload: &mut PayloadBuffer,
        boundary: &str,
    ) -> Poll<Option<Result<Bytes, MultipartError>>> {
        let mut pos = 0;
        let len = payload.buf.len();
        if len == 0 {
            return if payload.eof {
                Poll::Ready(Some(Err(MultipartError::Incomplete)))
            } else {
                Poll::Pending
            };
        }
        // check boundary
        if len > 4 && payload.buf[0] == b'\r' {
            let b_len = if &payload.buf[..2] == b"\r\n" && &payload.buf[2..4] == b"--" {
                Some(4)
            } else if &payload.buf[1..3] == b"--" {
                Some(3)
            } else {
                None
            };
            if let Some(b_len) = b_len {
                let b_size = boundary.len() + b_len;
                if len < b_size {
                    return Poll::Pending;
                } else if &payload.buf[b_len..b_size] == boundary.as_bytes() {
                    // found boundary
                    return Poll::Ready(None);
                }
            }
        }
        loop {
            return if let Some(idx) = twoway::find_bytes(&payload.buf[pos..], b"\r") {
                let cur = pos + idx;
                // check if we have enough data for boundary detection
                if cur + 4 > len {
                    if cur > 0 {
                        Poll::Ready(Some(Ok(payload.buf.split_to(cur).freeze())))
                    } else {
                        Poll::Pending
                    }
                } else {
                    // check boundary
                    if (&payload.buf[cur..cur + 2] == b"\r\n"
                        && &payload.buf[cur + 2..cur + 4] == b"--")
                        || (&payload.buf[cur..=cur] == b"\r"
                            && &payload.buf[cur + 1..cur + 3] == b"--")
                    {
                        if cur != 0 {
                            // return buffer
                            Poll::Ready(Some(Ok(payload.buf.split_to(cur).freeze())))
                        } else {
                            pos = cur + 1;
                            continue;
                        }
                    } else {
                        // not boundary
                        pos = cur + 1;
                        continue;
                    }
                }
            } else {
                Poll::Ready(Some(Ok(payload.buf.split().freeze())))
            };
        }
    }
fn read_stream ( payload : & mut PayloadBuffer , boundary : & str , ) -> Poll < Option < Result < Bytes , MultipartError > > > { let mut pos = 0 ; let len = payload . buf . len ( ) ; if len == 0 { return if payload . eof { Poll :: Ready ( Some ( Err ( MultipartError :: Incomplete ) ) ) } else { Poll :: Pending } ; } // check boundary if len > 4 && payload . buf [ 0 ] == b'\r' { let b_len = if & payload . buf [ .. 2 ] == b" \r \n " && & payload . buf [ 2 .. 4 ] == b" " { Some ( 4 ) } else if & payload . buf [ 1 .. 3 ] == b" " { Some ( 3 ) } else { None } ; if let Some ( b_len ) = b_len { let b_size = boundary . len ( ) + b_len ; if len < b_size { return Poll :: Pending ; } else if & payload . buf [ b_len .. b_size ] == boundary . as_bytes ( ) { // found boundary return Poll :: Ready ( None ) ; } } } loop { return if let Some ( idx ) = twoway :: find_bytes ( & payload . buf [ pos .. ] , b" \r " ) { let cur = pos + idx ; // check if we have enough data for boundary detection if cur + 4 > len { if cur > 0 { Poll :: Ready ( Some ( Ok ( payload . buf . split_to ( cur ) . freeze ( ) ) ) ) } else { Poll :: Pending } } else { // check boundary if ( & payload . buf [ cur .. cur + 2 ] == b" \r \n " && & payload . buf [ cur + 2 .. cur + 4 ] == b" " ) || ( & payload . buf [ cur ..= cur ] == b" \r " && & payload . buf [ cur + 1 .. cur + 3 ] == b" " ) { if cur != 0 { // return buffer Poll :: Ready ( Some ( Ok ( payload . buf . split_to ( cur ) . freeze ( ) ) ) ) } else { pos = cur + 1 ; continue ; } } else { // not boundary pos = cur + 1 ; continue ; } } } else { Poll :: Ready ( Some ( Ok ( payload . buf . split ( ) . freeze ( ) ) ) ) } ; } }
Reads content chunk of body part with unknown length.
Reads content chunk of body part with unknown length .
payload
&mut PayloadBuffer
boundary
&str
payload
&mut PayloadBuffer
boundary
&str