Show / Hide Table of Contents

Class LzwInputStream

This filter stream is used to decompress a LZW format stream. Specifically, a stream that uses the LZC compression method. This file format is usually associated with the .Z file extension.

See http://en.wikipedia.org/wiki/Compress See http://wiki.wxwidgets.org/Development:_Z_File_Format

The file header consists of 3 (or optionally 4) bytes. The first two bytes contain the magic marker "0x1f 0x9d", followed by a byte of flags.

Based on Java code by Ronald Tschalar, which in turn was based on the unlzw.c code in the gzip package.

Inheritance
System.Object
System.MarshalByRefObject
System.IO.Stream
LzwInputStream
Implements
System.IDisposable
Inherited Members
System.IO.Stream.Null
System.IO.Stream.BeginRead(System.Byte[], System.Int32, System.Int32, System.AsyncCallback, System.Object)
System.IO.Stream.BeginWrite(System.Byte[], System.Int32, System.Int32, System.AsyncCallback, System.Object)
System.IO.Stream.Close()
System.IO.Stream.CopyTo(System.IO.Stream)
System.IO.Stream.CopyTo(System.IO.Stream, System.Int32)
System.IO.Stream.CopyToAsync(System.IO.Stream)
System.IO.Stream.CopyToAsync(System.IO.Stream, System.Int32)
System.IO.Stream.CopyToAsync(System.IO.Stream, System.Int32, System.Threading.CancellationToken)
System.IO.Stream.CreateWaitHandle()
System.IO.Stream.Dispose()
System.IO.Stream.EndRead(System.IAsyncResult)
System.IO.Stream.EndWrite(System.IAsyncResult)
System.IO.Stream.FlushAsync()
System.IO.Stream.FlushAsync(System.Threading.CancellationToken)
System.IO.Stream.ObjectInvariant()
System.IO.Stream.ReadAsync(System.Byte[], System.Int32, System.Int32)
System.IO.Stream.ReadAsync(System.Byte[], System.Int32, System.Int32, System.Threading.CancellationToken)
System.IO.Stream.Synchronized(System.IO.Stream)
System.IO.Stream.WriteAsync(System.Byte[], System.Int32, System.Int32)
System.IO.Stream.WriteAsync(System.Byte[], System.Int32, System.Int32, System.Threading.CancellationToken)
System.IO.Stream.CanTimeout
System.IO.Stream.ReadTimeout
System.IO.Stream.WriteTimeout
System.MarshalByRefObject.GetLifetimeService()
System.MarshalByRefObject.InitializeLifetimeService()
System.MarshalByRefObject.MemberwiseClone(System.Boolean)
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: ICSharpCode.SharpZipLib.Lzw
Assembly: ICSharpCode.SharpZipLib.dll
Syntax
public class LzwInputStream : Stream, IDisposable
Examples

This sample shows how to unzip a compressed file

using System;
using System.IO;

using ICSharpCode.SharpZipLib.Core;
using ICSharpCode.SharpZipLib.LZW;

class MainClass
{
    public static void Main(string[] args)
    {
        using (Stream inStream = new LzwInputStream(File.OpenRead(args[0])))
        using (FileStream outStream = File.Create(Path.GetFileNameWithoutExtension(args[0]))) {
            byte[] buffer = new byte[4096];
            StreamUtils.Copy(inStream, outStream, buffer);
                        // OR
                        inStream.Read(buffer, 0, buffer.Length);
                        // now do something with the buffer
        }
    }
}

Constructors

| Improve this Doc View Source

LzwInputStream(Stream)

Creates a LzwInputStream

Declaration
public LzwInputStream(Stream baseInputStream)
Parameters
Type Name Description
System.IO.Stream baseInputStream

The stream to read compressed data from (baseInputStream LZW format)

Properties

| Improve this Doc View Source

CanRead

Gets a value indicating whether the current stream supports reading

Declaration
public override bool CanRead { get; }
Property Value
Type Description
System.Boolean
Overrides
System.IO.Stream.CanRead
| Improve this Doc View Source

CanSeek

Gets a value of false indicating seeking is not supported for this stream.

Declaration
public override bool CanSeek { get; }
Property Value
Type Description
System.Boolean
Overrides
System.IO.Stream.CanSeek
| Improve this Doc View Source

CanWrite

Gets a value of false indicating that this stream is not writeable.

Declaration
public override bool CanWrite { get; }
Property Value
Type Description
System.Boolean
Overrides
System.IO.Stream.CanWrite
| Improve this Doc View Source

IsStreamOwner

Gets or sets a flag indicating ownership of underlying stream. When the flag is true System.IO.Stream.Dispose() will close the underlying stream also.

Declaration
public bool IsStreamOwner { get; set; }
Property Value
Type Description
System.Boolean
Remarks

The default value is true.

| Improve this Doc View Source

Length

A value representing the length of the stream in bytes.

Declaration
public override long Length { get; }
Property Value
Type Description
System.Int64
Overrides
System.IO.Stream.Length
| Improve this Doc View Source

Position

The current position within the stream. Throws a NotSupportedException when attempting to set the position

Declaration
public override long Position { get; set; }
Property Value
Type Description
System.Int64
Overrides
System.IO.Stream.Position
Exceptions
Type Condition
System.NotSupportedException

Attempting to set the position

Methods

| Improve this Doc View Source

Dispose(Boolean)

Closes the input stream. When IsStreamOwner is true the underlying stream is also closed.

Declaration
protected override void Dispose(bool disposing)
Parameters
Type Name Description
System.Boolean disposing
Overrides
System.IO.Stream.Dispose(System.Boolean)
| Improve this Doc View Source

Flush()

Flushes the baseInputStream

Declaration
public override void Flush()
Overrides
System.IO.Stream.Flush()
| Improve this Doc View Source

Read(Byte[], Int32, Int32)

Reads decompressed data into the provided buffer byte array

Declaration
public override int Read(byte[] buffer, int offset, int count)
Parameters
Type Name Description
System.Byte[] buffer

The array to read and decompress data into

System.Int32 offset

The offset indicating where the data should be placed

System.Int32 count

The number of bytes to decompress

Returns
Type Description
System.Int32

The number of bytes read. Zero signals the end of stream

Overrides
System.IO.Stream.Read(System.Byte[], System.Int32, System.Int32)
| Improve this Doc View Source

ReadByte()

See System.IO.Stream.ReadByte()

Declaration
public override int ReadByte()
Returns
Type Description
System.Int32
Overrides
System.IO.Stream.ReadByte()
| Improve this Doc View Source

Seek(Int64, SeekOrigin)

Sets the position within the current stream Always throws a NotSupportedException

Declaration
public override long Seek(long offset, SeekOrigin origin)
Parameters
Type Name Description
System.Int64 offset

The relative offset to seek to.

System.IO.SeekOrigin origin

The System.IO.SeekOrigin defining where to seek from.

Returns
Type Description
System.Int64

The new position in the stream.

Overrides
System.IO.Stream.Seek(System.Int64, System.IO.SeekOrigin)
Exceptions
Type Condition
System.NotSupportedException

Any access

| Improve this Doc View Source

SetLength(Int64)

Set the length of the current stream Always throws a NotSupportedException

Declaration
public override void SetLength(long value)
Parameters
Type Name Description
System.Int64 value

The new length value for the stream.

Overrides
System.IO.Stream.SetLength(System.Int64)
Exceptions
Type Condition
System.NotSupportedException

Any access

| Improve this Doc View Source

Write(Byte[], Int32, Int32)

Writes a sequence of bytes to stream and advances the current position This method always throws a NotSupportedException

Declaration
public override void Write(byte[] buffer, int offset, int count)
Parameters
Type Name Description
System.Byte[] buffer

The buffer containing data to write.

System.Int32 offset

The offset of the first byte to write.

System.Int32 count

The number of bytes to write.

Overrides
System.IO.Stream.Write(System.Byte[], System.Int32, System.Int32)
Exceptions
Type Condition
System.NotSupportedException

Any access

| Improve this Doc View Source

WriteByte(Byte)

Writes one byte to the current stream and advances the current position Always throws a NotSupportedException

Declaration
public override void WriteByte(byte value)
Parameters
Type Name Description
System.Byte value

The byte to write.

Overrides
System.IO.Stream.WriteByte(System.Byte)
Exceptions
Type Condition
System.NotSupportedException

Any access

Implements

System.IDisposable
  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2000-2022 SharpZipLib Contributors