 USING: multiline kernel sequences io splitting fry namespaces
 http.parsers hashtables assocs combinators ascii io.files.unique
 accessors io.encodings.binary io.files byte-arrays math
-io.streams.string combinators.short-circuit strings ;
+io.streams.string combinators.short-circuit strings math.order ;
 IN: mime.multipart
 
 CONSTANT: buffer-size 65536

    [ nip ] [ start ] 2bi [
        cut-slice
        [ mime-write ]
        [ over current-separator>> length tail-slice >>bytes ] bi*
    ] [
        drop
        dup [ bytes>> ] [ current-separator>> ] bi split-bytes
        [ mime-write ] when*
        >>bytes fill-bytes dup end-of-stream?>> [ dump-until-separator ] unless
    ] if* ;


    dup end-of-stream?>> [ process-header parse-multipart-loop ] unless ;

: parse-multipart ( separator -- mime-parts )
    <multipart> parse-beginning fill-bytes parse-multipart-loop
    mime-parts>> ;
