Axiom.FileSystem.ZipArchive.Open C# (CSharp) Method

Open() public method

public Open ( string filename, bool readOnly ) : Stream
filename string
readOnly bool
return Stream
		public override Stream Open( string filename, bool readOnly )
		{
			ZipEntry entry;

			// we will put the decompressed data into a memory stream
			MemoryStream output = new MemoryStream();

			Load();

			// get the first entry 
			entry = _zipStream.GetNextEntry();

			// loop through all the entries until we find the requested one
			while ( entry != null )
			{
				if ( entry.Name.ToLower() == filename.ToLower() )
				{
					break;
				}

				// look at the next file in the list
				entry = _zipStream.GetNextEntry();
			}

			if ( entry == null )
			{
				return null;
			}

			// write the data to the output stream
			int size = 2048;
			byte[] data = new byte[ 2048 ];
			while ( true )
			{
				size = _zipStream.Read( data, 0, data.Length );
				if ( size > 0 )
				{
					output.Write( data, 0, size );
				}
				else
				{
					break;
				}
			}

			// reset the position to make sure it is at the beginning of the stream
			output.Position = 0;
			return output;
		}