CountingStream Class

DotNetZip

Ionic Zip Library v1.9.1.6 CountingStream Class
ReferenceIonic.ZipCountingStream
A decorator stream. It wraps another stream, and performs bookkeeping to keep track of the stream Position.
Declaration Syntax
C# Visual Basic Visual C++
public class CountingStream : Stream
Public Class CountingStream _
	Inherits Stream
public ref class CountingStream : public Stream
Members
All Members Constructors Methods Properties



Icon Member Description
CountingStream(Stream)
The constructor.

Adjust(Int64)
Adjust the byte count on the stream.

BeginRead(array<Byte>[]()[][], Int32, Int32, AsyncCallback, Object) HostProtectionAttribute.
Begins an asynchronous read operation.
(Inherited from Stream.)
BeginWrite(array<Byte>[]()[][], Int32, Int32, AsyncCallback, Object) HostProtectionAttribute.
Begins an asynchronous write operation.
(Inherited from Stream.)
BytesRead
the count of bytes that have been read from the stream.

BytesWritten
The count of bytes written out to the stream.

CanRead
Whether the stream can be read.
(Overrides Stream.CanRead.)
CanSeek
Whether it is possible to call Seek() on the stream.
(Overrides Stream.CanSeek.)
CanTimeout
Gets a value that determines whether the current stream can time out.
(Inherited from Stream.)
CanWrite
Whether it is possible to call Write() on the stream.
(Overrides Stream.CanWrite.)
Close()()()()
Closes the current stream and releases any resources (such as sockets and file handles) associated with the current stream.
(Inherited from Stream.)
ComputedPosition
Returns the sum of number of bytes written, plus the initial offset before writing.

CreateObjRef(Type)
Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
(Inherited from MarshalByRefObject.)
CreateWaitHandle()()()() Obsolete.
Allocates a WaitHandle object.
(Inherited from Stream.)
Dispose()()()()
Releases all resources used by the Stream.
(Inherited from Stream.)
Dispose(Boolean)
Releases the unmanaged resources used by the Stream and optionally releases the managed resources.
(Inherited from Stream.)
EndRead(IAsyncResult)
Waits for the pending asynchronous read to complete.
(Inherited from Stream.)
EndWrite(IAsyncResult)
Ends an asynchronous write operation.
(Inherited from Stream.)
Equals(Object)
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Finalize()()()()
Allows an Object to attempt to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection.
(Inherited from Object.)
Flush()()()()
Flushes the underlying stream.
(Overrides Stream.Flush()()()().)
GetHashCode()()()()
Serves as a hash function for a particular type.
(Inherited from Object.)
GetLifetimeService()()()()
Retrieves the current lifetime service object that controls the lifetime policy for this instance.
(Inherited from MarshalByRefObject.)
GetType()()()()
Gets the Type of the current instance.
(Inherited from Object.)
InitializeLifetimeService()()()()
Obtains a lifetime service object to control the lifetime policy for this instance.
(Inherited from MarshalByRefObject.)
Length
The length of the underlying stream.
(Overrides Stream.Length.)
MemberwiseClone(Boolean)
Creates a shallow copy of the current MarshalByRefObject object.
(Inherited from MarshalByRefObject.)
MemberwiseClone()()()()
Creates a shallow copy of the current Object.
(Inherited from Object.)
Position
The Position of the stream.
(Overrides Stream.Position.)
Read(array<Byte>[]()[][], Int32, Int32)
The read method.
(Overrides Stream.Read(array<Byte>[]()[][], Int32, Int32).)
ReadByte()()()()
Reads a byte from the stream and advances the position within the stream by one byte, or returns -1 if at the end of the stream.
(Inherited from Stream.)
ReadTimeout
Gets or sets a value, in miliseconds, that determines how long the stream will attempt to read before timing out.
(Inherited from Stream.)
Seek(Int64, SeekOrigin)
Seek in the stream.
(Overrides Stream.Seek(Int64, SeekOrigin).)
SetLength(Int64)
Set the length of the underlying stream. Be careful with this!
(Overrides Stream.SetLength(Int64).)
ToString()()()()
Returns a String that represents the current Object.
(Inherited from Object.)
WrappedStream
Gets the wrapped stream.

Write(array<Byte>[]()[][], Int32, Int32)
Write data into the stream.
(Overrides Stream.Write(array<Byte>[]()[][], Int32, Int32).)
WriteByte(Byte)
Writes a byte to the current position in the stream and advances the position within the stream by one byte.
(Inherited from Stream.)
WriteTimeout
Gets or sets a value, in miliseconds, that determines how long the stream will attempt to write before timing out.
(Inherited from Stream.)
Remarks

In some cases, it is not possible to get the Position of a stream, let's say, on a write-only output stream like ASP.NET's Response.OutputStream, or on a different write-only stream provided as the destination for the zip by the application. In this case, programmers can use this counting stream to count the bytes read or written.

Consider the scenario of an application that saves a self-extracting archive (SFX), that uses a custom SFX stub.

Saving to a filesystem file, the application would open the filesystem file (getting a FileStream), save the custom sfx stub into it, and then call ZipFile.Save(), specifying the same FileStream. ZipFile.Save() does the right thing for the zipentry offsets, by inquiring the Position of the FileStream before writing any data, and then adding that initial offset into any ZipEntry offsets in the zip directory. Everything works fine.

Now suppose the application is an ASPNET application and it saves directly to Response.OutputStream. It's not possible for DotNetZip to inquire the Position, so the offsets for the SFX will be wrong.

The workaround is for the application to use this class to wrap HttpResponse.OutputStream, then write the SFX stub and the ZipFile into that wrapper stream. Because ZipFile.Save() can inquire the Position, it will then do the right thing with the offsets.

Inheritance Hierarchy
Object
MarshalByRefObject
  Stream
    CountingStream

Assembly: Ionic.Zip (Module: Ionic.Zip) Version: 1.9.1.8 (1.9.1.8)