mime.multipart: Simplify the code a bit.

Fixes #2107
freebsd-work
Doug Coleman 2019-01-21 15:08:07 -06:00
parent d73fb5f80f
commit 0ae9b17734
2 changed files with 16 additions and 10 deletions

View File

@ -77,3 +77,10 @@ SYMBOL: mime-test-server
[ [
] with-test-server ] with-test-server
] unit-test ] unit-test
[
"--\r\n\r\n" <string-reader> [
"\r\n\r\n" <multipart>
"\r\n\r\n" parse-multipart
] with-input-stream
] [ mime-decoding-ran-out-of-bytes? ] must-fail-with

View File

@ -40,20 +40,19 @@ C: <mime-variable> mime-variable
[ '[ _ B{ } append-as ] change-bytes ] [ '[ _ B{ } append-as ] change-bytes ]
[ t >>end-of-stream? ] if* ; [ t >>end-of-stream? ] if* ;
: split-bytes ( bytes separator -- leftover-bytes safe-to-dump ) ERROR: mime-decoding-ran-out-of-bytes ;
dupd [ length ] bi@ 1 - - short cut-slice swap ;
: dump-until-separator ( multipart -- multipart ) : dump-until-separator ( multipart -- multipart )
dup [ ] [ current-separator>> ] [ bytes>> ] tri
[ current-separator>> ] [ bytes>> ] bi dup [ mime-decoding-ran-out-of-bytes ] unless
[ nip ] [ subseq-start ] 2bi [ 2dup subseq-start [
cut-slice cut-slice
[ mime-write ] [ mime-write ]
[ over current-separator>> length short tail-slice >>bytes ] bi* [ swap length tail-slice >>bytes ] bi*
] [ ] [
drop tuck [ length ] bi@ - 1 - cut-slice
dup [ bytes>> ] [ current-separator>> ] bi split-bytes mime-write [ mime-write ]
>>bytes fill-bytes dup end-of-stream?>> [ dump-until-separator ] unless [ >>bytes ] bi* fill-bytes
dup end-of-stream?>> [ dump-until-separator ] unless
] if* ; ] if* ;
: dump-string ( multipart separator -- multipart string ) : dump-string ( multipart separator -- multipart string )