fix how mime.multipart saves files
parent
24599a6437
commit
a1f58d5df1
|
@ -3,7 +3,7 @@
|
||||||
USING: multiline kernel sequences io splitting fry namespaces
|
USING: multiline kernel sequences io splitting fry namespaces
|
||||||
http.parsers hashtables assocs combinators ascii io.files.unique
|
http.parsers hashtables assocs combinators ascii io.files.unique
|
||||||
accessors io.encodings.binary io.files byte-arrays math
|
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
|
IN: mime.multipart
|
||||||
|
|
||||||
CONSTANT: buffer-size 65536
|
CONSTANT: buffer-size 65536
|
||||||
|
@ -45,11 +45,7 @@ ERROR: end-of-stream multipart ;
|
||||||
dup bytes>> [ fill-bytes ] unless ;
|
dup bytes>> [ fill-bytes ] unless ;
|
||||||
|
|
||||||
: split-bytes ( bytes separator -- leftover-bytes safe-to-dump )
|
: split-bytes ( bytes separator -- leftover-bytes safe-to-dump )
|
||||||
2dup [ length ] [ length 1- ] bi* < [
|
dupd [ length ] bi@ 1- - short cut-slice swap ;
|
||||||
drop f
|
|
||||||
] [
|
|
||||||
length 1- cut-slice swap
|
|
||||||
] if ;
|
|
||||||
|
|
||||||
: dump-until-separator ( multipart -- multipart )
|
: dump-until-separator ( multipart -- multipart )
|
||||||
dup
|
dup
|
||||||
|
@ -57,11 +53,10 @@ ERROR: end-of-stream multipart ;
|
||||||
[ nip ] [ start ] 2bi [
|
[ nip ] [ start ] 2bi [
|
||||||
cut-slice
|
cut-slice
|
||||||
[ mime-write ]
|
[ mime-write ]
|
||||||
[ over current-separator>> length tail-slice >>bytes ] bi*
|
[ over current-separator>> length short tail-slice >>bytes ] bi*
|
||||||
] [
|
] [
|
||||||
drop
|
drop
|
||||||
dup [ bytes>> ] [ current-separator>> ] bi split-bytes
|
dup [ bytes>> ] [ current-separator>> ] bi split-bytes mime-write
|
||||||
[ mime-write ] when*
|
|
||||||
>>bytes fill-bytes dup end-of-stream?>> [ dump-until-separator ] unless
|
>>bytes fill-bytes dup end-of-stream?>> [ dump-until-separator ] unless
|
||||||
] if* ;
|
] if* ;
|
||||||
|
|
||||||
|
@ -70,10 +65,10 @@ ERROR: end-of-stream multipart ;
|
||||||
[ dump-until-separator ] with-string-writer ;
|
[ dump-until-separator ] with-string-writer ;
|
||||||
|
|
||||||
: read-header ( multipart -- multipart )
|
: read-header ( multipart -- multipart )
|
||||||
"\r\n\r\n" dump-string dup "--\r" = [
|
dup bytes>> "--\r\n" sequence= [
|
||||||
drop
|
t >>end-of-stream?
|
||||||
] [
|
] [
|
||||||
parse-headers >>header
|
"\r\n\r\n" dump-string parse-headers >>header
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
: empty-name? ( string -- ? )
|
: empty-name? ( string -- ? )
|
||||||
|
@ -156,5 +151,5 @@ ERROR: no-content-disposition multipart ;
|
||||||
dup end-of-stream?>> [ process-header parse-multipart-loop ] unless ;
|
dup end-of-stream?>> [ process-header parse-multipart-loop ] unless ;
|
||||||
|
|
||||||
: parse-multipart ( separator -- mime-parts )
|
: parse-multipart ( separator -- mime-parts )
|
||||||
<multipart> parse-beginning parse-multipart-loop
|
<multipart> parse-beginning fill-bytes parse-multipart-loop
|
||||||
mime-parts>> ;
|
mime-parts>> ;
|
||||||
|
|
Loading…
Reference in New Issue