> in any case, as Ry said, clear library candidate. with Ruby and C versions.. any takers?
I plan to write the parser in c at some point in the next month - I
haven't been able to find a suitable existing c library. If anyone
else wants to take a crack at it, extracting some of Zed and Ezra's
string searching code might be useful:
http://github.com/ezmobius/bmhsearch/tree/master
The algorithm is roughly
1. get the boundary from Mongrel parser
CONTENT_TYPE: multipart/form-data.*boundary=\"?([^\";,]+)
2. use zed's string search thing to split input - put (beginning,
end)
tuples onto stack
3. rewind input
while( part = part_stack.pop )
4a. Parse headers
filename = head[/Content-Disposition:.* filename="?([^\";]*)"?/
ni, 1]
content_type = head[/Content-Type: (.*)\r\n/ni, 1]
name = head[/Content-Disposition:.* name="?([^\";]*)"?/ni, 1]
4b. Read the body of the part either into tempfile or into memory
4c. push (body, filename, content_type, name) onto output_stack
end
ry