Parses multipart MIME messages.
require "mime/multipart"
multipart = "--aA40\r\nContent-Type: text/plain\r\n\r\nbody\r\n--aA40--"
parser = MIME::Multipart::Parser.new(IO::Memory.new(multipart), "aA40")
while parser.has_next?
parser.next do |headers, io|
headers["Content-Type"] # => "text/plain"
io.gets_to_end # => "body"
end
end Please note that the IO object yielded by #next is only valid until the block returns.
Creates a new Multipart::Parser which parses io with multipart boundary boundary.
True if #next can be called legally.
Parses the next body part and yields headers as HTTP::Headers and the body text as an IO.
Reference
Reference
Object
Object
Creates a new Multipart::Parser which parses io with multipart boundary boundary.
Parses the next body part and yields headers as HTTP::Headers and the body text as an IO.
This method yields once instead of returning the values, because the IO object yielded to the block is only valid while the block is executing. The IO object will be closed as soon as the block returns. To store the content of the body part for longer than the block, the IO must be read into memory.
require "mime/multipart" multipart = "--aA40\r\nContent-Type: text/plain\r\n\r\nbody\r\n--aA40--" parser = MIME::Multipart::Parser.new(IO::Memory.new(multipart), "aA40") parser.next do |headers, io| headers["Content-Type"] # => "text/plain" io.gets_to_end # => "body" end
© 2012–2020 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.35.1/MIME/Multipart/Parser.html