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
- Attribute.cs
- DesignBindingConverter.cs
- ZipIOExtraFieldElement.cs
- StructuredTypeEmitter.cs
- DetailsViewUpdatedEventArgs.cs
- ACE.cs
- BCLDebug.cs
- ImageListDesigner.cs
- ManipulationDevice.cs
- PipelineModuleStepContainer.cs
- CultureMapper.cs
- XPathCompileException.cs
- TypefaceMetricsCache.cs
- VectorCollection.cs
- CommunicationObjectAbortedException.cs
- ISessionStateStore.cs
- ControlValuePropertyAttribute.cs
- Parallel.cs
- VisualBasicSettingsHandler.cs
- ConfigurationLocationCollection.cs
- Registry.cs
- LabelInfo.cs
- EndpointReference.cs
- ThreadStartException.cs
- XmlFormatWriterGenerator.cs
- Line.cs
- HtmlInputText.cs
- ObjectConverter.cs
- FileDialogCustomPlace.cs
- TouchFrameEventArgs.cs
- DefaultValueConverter.cs
- SymLanguageVendor.cs
- ReflectionUtil.cs
- PlainXmlWriter.cs
- DateTimeConverter.cs
- SafeUserTokenHandle.cs
- QuotedStringFormatReader.cs
- StyleCollection.cs
- PenLineJoinValidation.cs
- InkSerializer.cs
- ObjectStateEntryBaseUpdatableDataRecord.cs
- HtmlShim.cs
- ModifyActivitiesPropertyDescriptor.cs
- FixedPageAutomationPeer.cs
- AtomParser.cs
- XNodeNavigator.cs
- PasswordTextNavigator.cs
- PipelineModuleStepContainer.cs
- HtmlControlDesigner.cs
- ResourceReferenceExpressionConverter.cs
- MatrixCamera.cs
- WeakRefEnumerator.cs
- GroupBox.cs
- TypeBuilder.cs
- Int16AnimationBase.cs
- UnsafeNativeMethods.cs
- RecognizedPhrase.cs
- SystemIcons.cs
- ReturnType.cs
- BitmapMetadata.cs
- BrowsableAttribute.cs
- SmtpNegotiateAuthenticationModule.cs
- webbrowsersite.cs
- WebPartRestoreVerb.cs
- UnsettableComboBox.cs
- RootAction.cs
- ParserStreamGeometryContext.cs
- ReflectPropertyDescriptor.cs
- XmlILStorageConverter.cs
- BrowserDefinition.cs
- Gdiplus.cs
- WeakReference.cs
- BinaryConverter.cs
- ObfuscationAttribute.cs
- TargetConverter.cs
- OleDbStruct.cs
- Rethrow.cs
- HasCopySemanticsAttribute.cs
- log.cs
- MachineSettingsSection.cs
- DirectoryNotFoundException.cs
- VirtualPathUtility.cs
- Helpers.cs
- TemplateKey.cs
- EditorZone.cs
- Symbol.cs
- SecurityHelper.cs
- IdentityReference.cs
- DesignerVerb.cs
- DataGridColumnHeaderCollection.cs
- HierarchicalDataBoundControlAdapter.cs
- ZipIOZip64EndOfCentralDirectoryBlock.cs
- TreeNodeSelectionProcessor.cs
- ObjectListFieldCollection.cs
- PropertyItem.cs
- NameObjectCollectionBase.cs
- ObjectDataProvider.cs
- RTTrackingProfile.cs
- AnimatedTypeHelpers.cs
- RequestCachingSection.cs