C# DeflateStream WriteAsync(Byte[], Int32, Int32)
In this chapter you will learn:
- Get to know DeflateStream.WriteAsync(Byte[], Int32, Int32)
- Syntax for DeflateStream.WriteAsync(Byte[], Int32, Int32)
- Parameter for DeflateStream.WriteAsync(Byte[], Int32, Int32)
- Returns for DeflateStream.WriteAsync(Byte[], Int32, Int32)
- Example - DeflateStream.WriteAsync(Byte[], Int32, Int32)
Description
DeflateStream WriteAsync(Byte[], Int32, Int32)
Asynchronously
writes a sequence of bytes to the current stream and advances the current
position within this stream by the number of bytes written.
Syntax
DeflateStream.WriteAsync(Byte[], Int32, Int32)
has the following syntax.
[ComVisibleAttribute(false)]//from w w w .j a va 2 s. c om
[HostProtectionAttribute(SecurityAction.LinkDemand, ExternalThreading = true)]
public Task WriteAsync(
byte[] buffer,
int offset,
int count
)
Parameters
DeflateStream.WriteAsync(Byte[], Int32, Int32)
has the following parameters.
buffer
- The buffer to write data from.offset
- The zero-based byte offset in buffer from which to begin copying bytes to the stream.count
- The maximum number of bytes to write.
Returns
DeflateStream.WriteAsync(Byte[], Int32, Int32)
method returns A task that represents the asynchronous write operation.
Example
The following example shows how to write asynchronously to a file.
//from w w w.j a v a2 s . c o m
using System;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.IO;
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
UnicodeEncoding uniencoding = new UnicodeEncoding();
string filename = @"c:\Users\exampleuser\Documents\userinputlog.txt";
byte[] result = uniencoding.GetBytes(UserInput.Text);
using (FileStream SourceStream = File.Open(filename, FileMode.OpenOrCreate))
{
SourceStream.Seek(0, SeekOrigin.End);
await SourceStream.WriteAsync(result, 0, result.Length);
}
}
}
Next chapter...
What you will learn in the next chapter:
C# DeflateStream CanRead
C# DeflateStream CanSeek
C# DeflateStream CanTimeout
C# DeflateStream CanWrite
C# DeflateStream Length
C# DeflateStream Position
C# DeflateStream DeflateStream(Stream, Comp...
C# DeflateStream DeflateStream(Stream, Comp...
C# DeflateStream DeflateStream(Stream, Comp...
C# DeflateStream DeflateStream(Stream, Comp...
C# DeflateStream CopyTo(Stream)
C# DeflateStream CopyTo(Stream, Int32)
C# DeflateStream Read
C# DeflateStream ReadAsync(Byte[], Int32, I...
C# DeflateStream Write
C# DeflateStream CanSeek
C# DeflateStream CanTimeout
C# DeflateStream CanWrite
C# DeflateStream Length
C# DeflateStream Position
C# DeflateStream DeflateStream(Stream, Comp...
C# DeflateStream DeflateStream(Stream, Comp...
C# DeflateStream DeflateStream(Stream, Comp...
C# DeflateStream DeflateStream(Stream, Comp...
C# DeflateStream CopyTo(Stream)
C# DeflateStream CopyTo(Stream, Int32)
C# DeflateStream Read
C# DeflateStream ReadAsync(Byte[], Int32, I...
C# DeflateStream Write