C# DeflateStream ReadAsync(Byte[], Int32, Int32)

In this chapter you will learn:

  1. Get to know DeflateStream.ReadAsync(Byte[], Int32, Int32)
  2. Syntax for DeflateStream.ReadAsync(Byte[], Int32, Int32)
  3. Parameter for DeflateStream.ReadAsync(Byte[], Int32, Int32)
  4. Returns for DeflateStream.ReadAsync(Byte[], Int32, Int32)
  5. 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:

  1. Get to know DeflateStream.Write
  2. Syntax for DeflateStream.Write
  3. Parameter for DeflateStream.Write
  4. Returns for DeflateStream.Write
  5. Example - DeflateStream.Write
Home »
  C# Tutorial »
    System.IO.Compression »
      DeflateStream
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 WriteAsync(Byte[], Int32, ...