C# DeflateStream ReadAsync(Byte[], Int32, Int32)
In this chapter you will learn:
- Get to know DeflateStream.ReadAsync(Byte[], Int32, Int32)
- Syntax for DeflateStream.ReadAsync(Byte[], Int32, Int32)
- Parameter for DeflateStream.ReadAsync(Byte[], Int32, Int32)
- Returns for DeflateStream.ReadAsync(Byte[], Int32, Int32)
- Example - DeflateStream.ReadAsync(Byte[], Int32, Int32)
Description
DeflateStream ReadAsync(Byte[], Int32, Int32)
Asynchronously
reads a sequence of bytes from the current stream and advances the position
within the stream by the number of bytes read.
Syntax
DeflateStream.ReadAsync(Byte[], Int32, Int32)
has the following syntax.
[ComVisibleAttribute(false)]//from w w w. j a va 2s . c om
[HostProtectionAttribute(SecurityAction.LinkDemand, ExternalThreading = true)]
public Task<int> ReadAsync(
byte[] buffer,
int offset,
int count
)
Parameters
DeflateStream.ReadAsync(Byte[], Int32, Int32)
has the following parameters.
buffer
- The buffer to write the data into.offset
- The byte offset in buffer at which to begin writing data from the stream.count
- The maximum number of bytes to read.
Returns
DeflateStream.ReadAsync(Byte[], Int32, Int32)
method returns <
Example
The following example shows how to read from a file asynchronously.
// w ww. j a v a 2 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\log.txt";
byte[] result;
using (FileStream SourceStream = File.Open(filename, FileMode.Open))
{
result = new byte[SourceStream.Length];
await SourceStream.ReadAsync(result, 0, (int)SourceStream.Length);
}
UserInput.Text = uniencoding.GetString(result);
}
}
Next chapter...
What you will learn in the next chapter:
- Get to know DeflateStream.Write
- Syntax for DeflateStream.Write
- Parameter for DeflateStream.Write
- Returns for DeflateStream.Write
- Example - DeflateStream.Write
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 WriteAsync(Byte[], Int32, ...
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 WriteC# DeflateStream WriteAsync(Byte[], Int32, ...