Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / 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: 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. //------------------------------------------------------------------------------ // //// 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
- ColumnMapVisitor.cs
- GridViewActionList.cs
- PropertyTab.cs
- MonitoringDescriptionAttribute.cs
- UnsupportedPolicyOptionsException.cs
- SafeTimerHandle.cs
- RangeValuePattern.cs
- BitSet.cs
- TiffBitmapEncoder.cs
- AccessDataSource.cs
- CounterNameConverter.cs
- WebPartConnectionsEventArgs.cs
- DataGridViewRowHeightInfoNeededEventArgs.cs
- WebAdminConfigurationHelper.cs
- DefaultProfileManager.cs
- XmlProcessingInstruction.cs
- ReliableSessionBindingElementImporter.cs
- ToolStripSplitButton.cs
- BrowserCapabilitiesCodeGenerator.cs
- CancellationTokenRegistration.cs
- BitStream.cs
- ObjectDataSourceEventArgs.cs
- StringWriter.cs
- AttachInfo.cs
- RequestCachePolicy.cs
- VScrollProperties.cs
- HtmlLink.cs
- XmlSchemaSimpleContent.cs
- StretchValidation.cs
- Options.cs
- SchemaInfo.cs
- ObjectListCommandsPage.cs
- AnonymousIdentificationModule.cs
- PenContext.cs
- DetailsViewDeletedEventArgs.cs
- QueryReaderSettings.cs
- ResourceDescriptionAttribute.cs
- DataGridViewRowContextMenuStripNeededEventArgs.cs
- WpfSharedBamlSchemaContext.cs
- Byte.cs
- WebBrowserProgressChangedEventHandler.cs
- DirectoryInfo.cs
- ServiceNameElement.cs
- MediaElement.cs
- TreeNodeStyleCollection.cs
- SharedUtils.cs
- GridViewCellAutomationPeer.cs
- QilExpression.cs
- TransformPatternIdentifiers.cs
- UriTemplateTableMatchCandidate.cs
- MenuItem.cs
- ObjectPersistData.cs
- PropertyChangeTracker.cs
- FileCodeGroup.cs
- SubMenuStyleCollection.cs
- EntityDataSourceUtil.cs
- Transform3D.cs
- regiisutil.cs
- PeerToPeerException.cs
- SoapAttributes.cs
- TableLayoutRowStyleCollection.cs
- ServiceBehaviorElement.cs
- ThicknessKeyFrameCollection.cs
- TextBoxAutoCompleteSourceConverter.cs
- XmlIlGenerator.cs
- Propagator.JoinPropagator.cs
- DataGridViewSelectedColumnCollection.cs
- DataAdapter.cs
- SpellCheck.cs
- PixelFormat.cs
- RegexBoyerMoore.cs
- AspNetRouteServiceHttpHandler.cs
- CodeDomSerializerException.cs
- MainMenu.cs
- Internal.cs
- DecimalStorage.cs
- CompiledQuery.cs
- SafeArrayTypeMismatchException.cs
- XmlQueryRuntime.cs
- StaticResourceExtension.cs
- SizeF.cs
- ProfessionalColors.cs
- XmlDownloadManager.cs
- XamlStream.cs
- MultiTrigger.cs
- ModulesEntry.cs
- MembershipSection.cs
- dbenumerator.cs
- HtmlTernaryTree.cs
- XmlConvert.cs
- DesignerVerb.cs
- IFormattable.cs
- StrokeCollectionDefaultValueFactory.cs
- ServicePoint.cs
- ConfigurationValidatorAttribute.cs
- RequestCachingSection.cs
- PasswordBoxAutomationPeer.cs
- ReadOnlyTernaryTree.cs
- DefaultWorkflowSchedulerService.cs
- MemoryPressure.cs