/// <summary> /// Writes the MIME parts from streamIn to streams that are provided by the consumer. /// If the output stream is a FileStream, it is disposed after the data is written to the file. /// </summary> /// <param name="streamIn"></param> /// <param name="outputStreamGetter">A delegate that provides an output stream based on MIME part header values.</param> /// <param name="boundary"></param> public void WritePartsToStreams(Stream streamIn, StreamGetter outputStreamGetter, string boundary) { byte[] boundaryBytes = Encoding.UTF8.GetBytes("\r\n--" + boundary); _splitter.Init(streamIn); _splitter.WriteUntilPattern(Stream.Null, boundaryBytes); // Discard everything until the first boundary. _splitter.WriteBytes(Stream.Null, 2); // Skip CR-LF do { // Note that if streamOut is Stream.Null, it doesn't hurt anything to dispose it. Stream streamOut = outputStreamGetter(GetHeaders(streamIn)); _splitter.WriteUntilPattern(streamOut, boundaryBytes); // Grab the 2 bytes that follow the boundary. // The two bytes will be CR-LF for normal boundaries, but they will // be "--" for the terminating boundary. _scratchPadStream.Position = 0; _splitter.WriteBytes(_scratchPadStream, 2); if (streamOut is FileStream) { streamOut.Dispose(); } }while (!(_scratchPad[0] == 0x2d && _scratchPad[1] == 0x2d)); }
/// <summary> /// Writes the MIME parts from streamIn to streams that are provided by the consumer. /// If the output stream is a FileStream, it is disposed after the data is written to the file. /// </summary> /// <param name="streamIn"></param> /// <param name="outputStreamGetter">A delegate that provides an output stream based on MIME part header values.</param> /// <param name="boundary"></param> public void WritePartsToStreams(Stream streamIn, StreamGetter outputStreamGetter, string boundary) { byte[] boundaryBytes = Encoding.UTF8.GetBytes("\r\n--" + boundary); _splitter.Init(streamIn); _splitter.WriteUntilPattern(Stream.Null, boundaryBytes); // Discard everything until the first boundary. _splitter.WriteBytes(Stream.Null, 2); // Skip CR-LF do { // Note that if streamOut is Stream.Null, it doesn't hurt anything to dispose it. Stream streamOut = outputStreamGetter(GetHeaders(streamIn)); _splitter.WriteUntilPattern(streamOut, boundaryBytes); // Grab the 2 bytes that follow the boundary. // The two bytes will be CR-LF for normal boundaries, but they will // be "--" for the terminating boundary. _scratchPadStream.Position = 0; _splitter.WriteBytes(_scratchPadStream, 2); if (streamOut is FileStream) { streamOut.Dispose(); } } while (!(_scratchPad[0] == 0x2d && _scratchPad[1] == 0x2d)); }