Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Base / MS / Internal / IO / Packaging / DeflateEmulationStream.cs / 1305600 / 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: BruceMac: 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
- ResumeStoryboard.cs
- Byte.cs
- CfgParser.cs
- UdpUtility.cs
- FontFamily.cs
- AppDomainFactory.cs
- StartUpEventArgs.cs
- HelpEvent.cs
- AddDataControlFieldDialog.cs
- ClientSideQueueItem.cs
- ItemDragEvent.cs
- SQLBoolean.cs
- MessagePartDescription.cs
- versioninfo.cs
- TakeOrSkipWhileQueryOperator.cs
- CryptoKeySecurity.cs
- safelinkcollection.cs
- SRef.cs
- TimelineGroup.cs
- PickBranch.cs
- SqlDelegatedTransaction.cs
- CodeConditionStatement.cs
- XhtmlBasicFormAdapter.cs
- SafeSecurityHandles.cs
- SpellCheck.cs
- DoubleAnimationClockResource.cs
- TakeQueryOptionExpression.cs
- BufferedGraphics.cs
- ComEventsSink.cs
- DesignerProperties.cs
- TemplateControlCodeDomTreeGenerator.cs
- BrowserCapabilitiesCodeGenerator.cs
- PolygonHotSpot.cs
- QuotedPrintableStream.cs
- InputEventArgs.cs
- DesignerHelpers.cs
- TextTreeObjectNode.cs
- HyperLink.cs
- RowUpdatedEventArgs.cs
- XmlDocument.cs
- RegionIterator.cs
- ImmutableObjectAttribute.cs
- CaseCqlBlock.cs
- RemotingAttributes.cs
- Zone.cs
- ImageListUtils.cs
- ByteStreamGeometryContext.cs
- TextParagraphView.cs
- ProfilePropertySettingsCollection.cs
- WebCategoryAttribute.cs
- StrokeNodeEnumerator.cs
- ValidatorCompatibilityHelper.cs
- DictionaryContent.cs
- MetadataArtifactLoaderCompositeResource.cs
- TreeNodeSelectionProcessor.cs
- TextBlock.cs
- CodeCatchClauseCollection.cs
- ValidatorCompatibilityHelper.cs
- WebPartZoneBase.cs
- CompositeTypefaceMetrics.cs
- SqlDataSourceCache.cs
- CodeObjectCreateExpression.cs
- ClipboardProcessor.cs
- HttpFormatExtensions.cs
- AuthenticationServiceManager.cs
- HttpPostProtocolReflector.cs
- WebException.cs
- DrawListViewSubItemEventArgs.cs
- SpellerHighlightLayer.cs
- BaseAppDomainProtocolHandler.cs
- WCFBuildProvider.cs
- ScopedKnownTypes.cs
- TextEditorSelection.cs
- InfoCardSymmetricCrypto.cs
- XpsFixedDocumentReaderWriter.cs
- SeparatorAutomationPeer.cs
- ReaderWriterLock.cs
- UIServiceHelper.cs
- JsonGlobals.cs
- DataRowView.cs
- MimeTypeAttribute.cs
- PtsPage.cs
- State.cs
- ResourceExpressionEditor.cs
- XPathNodePointer.cs
- RegexWriter.cs
- DtdParser.cs
- CacheForPrimitiveTypes.cs
- oledbconnectionstring.cs
- ContainerControl.cs
- Descriptor.cs
- StringArrayConverter.cs
- RectangleHotSpot.cs
- KeyInfo.cs
- WebConfigurationHostFileChange.cs
- WindowsStatusBar.cs
- AdRotator.cs
- InvalidPropValue.cs
- RuleSet.cs
- RuleProcessor.cs