MailKit.Net.Imap.ImapLiteral.WriteTo C# (CSharp) Method

WriteTo() public method

Write the literal to the specified stream.
Writes the literal to the specified stream.
public WriteTo ( ImapStream stream, CancellationToken cancellationToken ) : void
stream ImapStream The stream.
cancellationToken System.Threading.CancellationToken The cancellation token.
return void
		public void WriteTo (ImapStream stream, CancellationToken cancellationToken)
		{
			if (Type == ImapLiteralType.String) {
				var bytes = (byte[]) Literal;
				stream.Write (bytes, 0, bytes.Length, cancellationToken);
				stream.Flush (cancellationToken);
				return;
			}

			if (Type == ImapLiteralType.MimeMessage) {
				var message = (MimeMessage) Literal;

				using (var s = new ProgressStream (stream, update)) {
					message.WriteTo (format, s, cancellationToken);
					s.Flush (cancellationToken);
					return;
				}
			}

			var literal = (Stream) Literal;
			var buf = new byte[4096];
			int nread;

			while ((nread = literal.Read (buf, 0, buf.Length)) > 0)
				stream.Write (buf, 0, nread, cancellationToken);

			stream.Flush (cancellationToken);
		}
	}