Table of Contents

Class BZip2InputStream

Namespace
Ionic.BZip2
Assembly
SunamoDotNetZip.dll

A read-only decorator stream that performs BZip2 decompression on Read.

public class BZip2InputStream : Stream, IAsyncDisposable, IDisposable
Inheritance
BZip2InputStream
Implements
Inherited Members
Extension Methods

Constructors

BZip2InputStream(Stream)

Create a BZip2InputStream, wrapping it around the given input Stream.

public BZip2InputStream(Stream input)

Parameters

input Stream

The stream from which to read compressed data

Remarks

The input stream will be closed when the BZip2InputStream is closed.

BZip2InputStream(Stream, bool)

Create a BZip2InputStream with the given stream, and specifying whether to leave the wrapped stream open when the BZip2InputStream is closed.

public BZip2InputStream(Stream input, bool leaveOpen)

Parameters

input Stream

The stream from which to read compressed data

leaveOpen bool

Whether to leave the input stream open, when the BZip2InputStream closes.

Examples

This example reads a bzip2-compressed file, decompresses it, and writes the decompressed data into a newly created file.

var fname = "logfile.log.bz2";
using (var fs = File.OpenRead(fname))
{
    using (var decompressor = new BZip2InputStream(fs))
    {
        var outFname = fname + ".decompressed";
        using (var output = File.Create(outFname))
        {
            byte[] buffer = new byte[2048];
            int n;
            while ((n = decompressor.Read(buffer, 0, buffer.Length)) > 0)
            {
                output.Write(buffer, 0, n);
            }
        }
    }
}

Properties

CanRead

Indicates whether the stream can be read.

public override bool CanRead { get; }

Property Value

bool

Remarks

The return value depends on whether the captive stream supports reading.

CanSeek

Indicates whether the stream supports Seek operations.

public override bool CanSeek { get; }

Property Value

bool

Remarks

Always returns false.

CanWrite

Indicates whether the stream can be written.

public override bool CanWrite { get; }

Property Value

bool

Remarks

The return value depends on whether the captive stream supports writing.

Length

Reading this property always throws a NotImplementedException.

public override long Length { get; }

Property Value

long

Position

The position of the stream pointer.

public override long Position { get; set; }

Property Value

long

Remarks

Setting this property always throws a NotImplementedException. Reading will return the total number of uncompressed bytes read in.

Methods

Close()

Close the stream.

public override void Close()

Dispose(bool)

Dispose the stream.

protected override void Dispose(bool disposing)

Parameters

disposing bool

indicates whether the Dispose method was invoked by user code.

Flush()

Flush the stream.

public override void Flush()

Read(byte[], int, int)

Read data from the stream.

public override int Read(byte[] buffer, int offset, int count)

Parameters

buffer byte[]

The buffer into which the read data should be placed.

offset int

the offset within that data array to put the first byte read.

count int

the number of bytes to read.

Returns

int

the number of bytes actually read

Remarks

To decompress a BZip2 data stream, create a BZip2InputStream, providing a stream that reads compressed data. Then call Read() on that BZip2InputStream, and the data read will be decompressed as you read.

A BZip2InputStream can be used only for Read(), not for Write().

ReadByte()

Read a single byte from the stream.

public override int ReadByte()

Returns

int

the byte read from the stream, or -1 if EOF

Seek(long, SeekOrigin)

Calling this method always throws a NotImplementedException.

public override long Seek(long offset, SeekOrigin origin)

Parameters

offset long

this is irrelevant, since it will always throw!

origin SeekOrigin

this is irrelevant, since it will always throw!

Returns

long

irrelevant!

SetLength(long)

Calling this method always throws a NotImplementedException.

public override void SetLength(long value)

Parameters

value long

this is irrelevant, since it will always throw!

Write(byte[], int, int)

Calling this method always throws a NotImplementedException.

public override void Write(byte[] buffer, int offset, int count)

Parameters

buffer byte[]

this parameter is never used

offset int

this parameter is never used

count int

this parameter is never used