C# Class HttpMultipartParser.StreamingMultipartFormDataParser

Provides methods to parse a multipart/form-data stream into it's parameters and file data.

A parameter is defined as any non-file data passed in the multipart stream. For example any form fields would be considered a parameter.

The parser determines if a section is a file or not based on the presence or absence of the filename argument for the Content-Type header. If filename is set then the section is assumed to be a file, otherwise it is assumed to be parameter data.

显示文件 Open project: Vodurden/Http-Multipart-Data-Parser Class Usage Examples

Public Methods

Method Description
Run ( ) : void

Begins executing the parser. This should be called after all handlers have been set.

StreamingMultipartFormDataParser ( Stream stream ) : System

Initializes a new instance of the StreamingMultipartFormDataParser class with an input stream. Boundary will be automatically detected based on the first line of input.

StreamingMultipartFormDataParser ( Stream stream, Encoding encoding ) : System

Initializes a new instance of the StreamingMultipartFormDataParser class with the input stream and stream encoding. Boundary is automatically detected.

StreamingMultipartFormDataParser ( Stream stream, Encoding encoding, int binaryBufferSize ) : System

Initializes a new instance of the StreamingMultipartFormDataParser class with the stream, input encoding and buffer size. Boundary is automatically detected.

StreamingMultipartFormDataParser ( Stream stream, string boundary ) : System

Initializes a new instance of the StreamingMultipartFormDataParser class with the boundary and input stream.

StreamingMultipartFormDataParser ( Stream stream, string boundary, Encoding encoding ) : System

Initializes a new instance of the StreamingMultipartFormDataParser class with the boundary, input stream and stream encoding.

StreamingMultipartFormDataParser ( Stream stream, string boundary, Encoding encoding, int binaryBufferSize ) : System

Initializes a new instance of the StreamingMultipartFormDataParser class with the boundary, stream, input encoding and buffer size.

Private Methods

Method Description
CalculateNewlineLength ( byte &data, int offset ) : int

Calculates the length of the next found newline. data[offset] is the start of the space to search.

DetectBoundary ( RebufferableBinaryReader reader ) : string

Detects the boundary from the input stream. Assumes that the current position of the reader is the start of the file and therefore the beginning of the boundary.

FindNextNewline ( byte &data, int offset, int maxBytes ) : int

Finds the next sequence of newlines in the input stream.

Parse ( RebufferableBinaryReader reader ) : void

Begins the parsing of the stream into objects.

ParseFilePart ( string>.Dictionary parameters, RebufferableBinaryReader reader ) : void

Parses a section of the stream that is known to be file data.

ParseParameterPart ( string>.Dictionary parameters, RebufferableBinaryReader reader ) : void

Parses a section of the stream that is known to be parameter data.

ParseSection ( RebufferableBinaryReader reader ) : void

Parses the header of the next section of the multipart stream and determines if it contains file data or parameter data.

SplitBySemicolonIgnoringSemicolonsInQuotes ( string line ) : IEnumerable

Splits a line by semicolons but ignores semicolons in quotes.

Method Details

Run() public method

Begins executing the parser. This should be called after all handlers have been set.
public Run ( ) : void
return void

StreamingMultipartFormDataParser() public method

Initializes a new instance of the StreamingMultipartFormDataParser class with an input stream. Boundary will be automatically detected based on the first line of input.
public StreamingMultipartFormDataParser ( Stream stream ) : System
stream Stream /// The stream containing the multipart data ///
return System

StreamingMultipartFormDataParser() public method

Initializes a new instance of the StreamingMultipartFormDataParser class with the input stream and stream encoding. Boundary is automatically detected.
public StreamingMultipartFormDataParser ( Stream stream, Encoding encoding ) : System
stream Stream /// The stream containing the multipart data ///
encoding System.Text.Encoding /// The encoding of the multipart data ///
return System

StreamingMultipartFormDataParser() public method

Initializes a new instance of the StreamingMultipartFormDataParser class with the stream, input encoding and buffer size. Boundary is automatically detected.
public StreamingMultipartFormDataParser ( Stream stream, Encoding encoding, int binaryBufferSize ) : System
stream Stream /// The stream containing the multipart data ///
encoding System.Text.Encoding /// The encoding of the multipart data ///
binaryBufferSize int /// The size of the buffer to use for parsing the multipart form data. This must be larger /// then (size of boundary + 4 + # bytes in newline). ///
return System

StreamingMultipartFormDataParser() public method

Initializes a new instance of the StreamingMultipartFormDataParser class with the boundary and input stream.
public StreamingMultipartFormDataParser ( Stream stream, string boundary ) : System
stream Stream /// The stream containing the multipart data ///
boundary string /// The multipart/form-data boundary. This should be the value /// returned by the request header. ///
return System

StreamingMultipartFormDataParser() public method

Initializes a new instance of the StreamingMultipartFormDataParser class with the boundary, input stream and stream encoding.
public StreamingMultipartFormDataParser ( Stream stream, string boundary, Encoding encoding ) : System
stream Stream /// The stream containing the multipart data ///
boundary string /// The multipart/form-data boundary. This should be the value /// returned by the request header. ///
encoding System.Text.Encoding /// The encoding of the multipart data ///
return System

StreamingMultipartFormDataParser() public method

Initializes a new instance of the StreamingMultipartFormDataParser class with the boundary, stream, input encoding and buffer size.
public StreamingMultipartFormDataParser ( Stream stream, string boundary, Encoding encoding, int binaryBufferSize ) : System
stream Stream /// The stream containing the multipart data ///
boundary string /// The multipart/form-data boundary. This should be the value /// returned by the request header. ///
encoding System.Text.Encoding /// The encoding of the multipart data ///
binaryBufferSize int /// The size of the buffer to use for parsing the multipart form data. This must be larger /// then (size of boundary + 4 + # bytes in newline). ///
return System