Code:
/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Base / MS / Internal / IO / Packaging / DeflateEmulationStream.cs / 1 / DeflateEmulationStream.cs
//------------------------------------------------------------------------------ // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // Description: // Implementation of a helper class that provides a fully functional Stream on a restricted functionality // Compression stream (System.IO.Compression.DeflateStream). // // History: // 10/05/2005: [....]: Split out from CompressEmulationStream //----------------------------------------------------------------------------- using System; using System.IO; using System.IO.Compression; // for DeflateStream using System.Diagnostics; using System.IO.Packaging; using System.Windows; namespace MS.Internal.IO.Packaging { //----------------------------------------------------- // // Internal Members // //----------------------------------------------------- ////// Emulates a fully functional stream using restricted functionality DeflateStream /// internal class DeflateEmulationTransform : IDeflateTransform { ////// Extract from DeflateStream to temp stream /// ///Caller is responsible for correctly positioning source and sink stream pointers before calling. public void Decompress(Stream source, Stream sink) { // for non-empty stream create deflate stream that can // actually decompress using (DeflateStream deflateStream = new DeflateStream( source, // source of compressed data CompressionMode.Decompress, // compress or decompress true)) // leave base stream open when the deflate stream is closed { int bytesRead = 0; do { bytesRead = deflateStream.Read(Buffer, 0, Buffer.Length); if (bytesRead > 0) sink.Write(Buffer, 0, bytesRead); } while (bytesRead > 0); } } ////// Compress from the temp stream into the base stream /// ///Caller is responsible for correctly positioning source and sink stream pointers before calling. public void Compress(Stream source, Stream sink) { // create deflate stream that can actually compress or decompress using (DeflateStream deflateStream = new DeflateStream( sink, // destination for compressed data CompressionMode.Compress, // compress or decompress true)) // leave base stream open when the deflate stream is closed { // persist to deflated stream from working stream int bytesRead = 0; do { bytesRead = source.Read(Buffer, 0, Buffer.Length); if (bytesRead > 0) deflateStream.Write(Buffer, 0, bytesRead); } while (bytesRead > 0); } // truncate if necessary and possible if (sink.CanSeek) sink.SetLength(sink.Position); } //------------------------------------------------------ // // Private Properties // //----------------------------------------------------- private byte[] Buffer { get { if (_buffer == null) _buffer = new byte[0x1000]; // 4k return _buffer; } } //------------------------------------------------------ // // Private Members // //------------------------------------------------------ private byte[] _buffer; // alloc and re-use to reduce memory fragmentation // this is safe because we are not thread-safe } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SqlClientWrapperSmiStream.cs
- BitmapMetadataBlob.cs
- Cloud.cs
- EditingCoordinator.cs
- DispatchChannelSink.cs
- SplitContainer.cs
- AccessibleObject.cs
- XmlText.cs
- Compress.cs
- _HeaderInfoTable.cs
- SubtreeProcessor.cs
- SafeFileHandle.cs
- CodeGeneratorOptions.cs
- ChtmlCommandAdapter.cs
- EventDescriptor.cs
- Mappings.cs
- ConfigXmlAttribute.cs
- WorkflowDesignerColors.cs
- RepeaterDataBoundAdapter.cs
- DtrList.cs
- WindowsFormsSynchronizationContext.cs
- Int32Rect.cs
- BaseCollection.cs
- SrgsItemList.cs
- RemoteWebConfigurationHostServer.cs
- SmtpException.cs
- Style.cs
- InputLangChangeEvent.cs
- DbCommandDefinition.cs
- AccessDataSource.cs
- RowUpdatedEventArgs.cs
- ObjectQueryExecutionPlan.cs
- WhitespaceRule.cs
- MemberHolder.cs
- COM2ICategorizePropertiesHandler.cs
- IndexerNameAttribute.cs
- RepeaterItemCollection.cs
- TextCharacters.cs
- HashHelper.cs
- ValidationErrorCollection.cs
- ByteAnimationBase.cs
- PostBackOptions.cs
- ObjectDataSourceMethodEventArgs.cs
- InplaceBitmapMetadataWriter.cs
- AssociatedControlConverter.cs
- Line.cs
- ConfigurationManagerInternalFactory.cs
- TableLayoutPanel.cs
- SendMailErrorEventArgs.cs
- XmlSchemaAttributeGroup.cs
- ListenerConnectionModeReader.cs
- Int64AnimationUsingKeyFrames.cs
- SqlCommand.cs
- WebPartMenu.cs
- ConfigXmlComment.cs
- ToolStripPanelRenderEventArgs.cs
- HttpFileCollection.cs
- EventLogConfiguration.cs
- PenThreadWorker.cs
- Utils.cs
- FileResponseElement.cs
- PanelStyle.cs
- XmlWrappingReader.cs
- TimeIntervalCollection.cs
- AppSettingsSection.cs
- PropertyGridView.cs
- MSHTMLHostUtil.cs
- SchemaCollectionCompiler.cs
- CopyAttributesAction.cs
- MLangCodePageEncoding.cs
- SchemaImporter.cs
- ClassDataContract.cs
- SpecularMaterial.cs
- odbcmetadatacollectionnames.cs
- PartialCachingControl.cs
- StrokeRenderer.cs
- TextMarkerSource.cs
- SpecialNameAttribute.cs
- ErrorWrapper.cs
- NCryptSafeHandles.cs
- GC.cs
- InkPresenter.cs
- CheckBoxPopupAdapter.cs
- Optimizer.cs
- CredentialCache.cs
- WorkflowMarkupSerializationException.cs
- TextServicesCompartmentEventSink.cs
- NameObjectCollectionBase.cs
- WorkflowStateRollbackService.cs
- Convert.cs
- GraphicsState.cs
- MediaScriptCommandRoutedEventArgs.cs
- IndentedWriter.cs
- AuthenticateEventArgs.cs
- InstancePersistenceContext.cs
- PathGeometry.cs
- GiveFeedbackEventArgs.cs
- ManualResetEvent.cs
- SmiSettersStream.cs
- SchemaMapping.cs