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
Implements
Inherited Members
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 SourceLzwInputStream(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 SourceCanRead
Gets a value indicating whether the current stream supports reading
Declaration
public override bool CanRead { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Overrides
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
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
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.
Length
A value representing the length of the stream in bytes.
Declaration
public override long Length { get; }
Property Value
Type | Description |
---|---|
System.Int64 |
Overrides
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
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | Attempting to set the position |
Methods
| Improve this Doc View SourceDispose(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
Flush()
Flushes the baseInputStream
Declaration
public override void Flush()
Overrides
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
ReadByte()
See System.IO.Stream.ReadByte()
Declaration
public override int ReadByte()
Returns
Type | Description |
---|---|
System.Int32 |
Overrides
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
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | Any access |
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
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | Any access |
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
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | Any access |
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
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | Any access |