Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Sys / System / IO / compression / CopyEncoder.cs / 1305376 / CopyEncoder.cs
namespace System.IO.Compression { using System.Diagnostics; internal class CopyEncoder { // padding for copy encoder formatting // - 1 byte for header // - 4 bytes for len, nlen private const int PaddingSize = 5; // max uncompressed deflate block size is 64K. private const int MaxUncompressedBlockSize = 65536; // null input means write an empty payload with formatting info. This is needed for the final block. public void GetBlock(DeflateInput input, OutputBuffer output, bool isFinal) { Debug.Assert(output != null); Debug.Assert(output.FreeBytes >= PaddingSize); // determine number of bytes to write int count = 0; if (input != null) { // allow space for padding and bits not yet flushed to buffer count = Math.Min(input.Count, output.FreeBytes - PaddingSize - output.BitsInBuffer); // we don't expect the output buffer to ever be this big (currently 4K), but we'll check this // just in case that changes. if (count > MaxUncompressedBlockSize - PaddingSize) { count = MaxUncompressedBlockSize - PaddingSize; } } // write header and flush bits if (isFinal) { output.WriteBits(FastEncoderStatics.BFinalNoCompressionHeaderBitCount, FastEncoderStatics.BFinalNoCompressionHeader); } else { output.WriteBits(FastEncoderStatics.NoCompressionHeaderBitCount, FastEncoderStatics.NoCompressionHeader); } // now we're aligned output.FlushBits(); // write len, nlen WriteLenNLen((ushort)count, output); // write uncompressed bytes if (input != null && count > 0) { output.WriteBytes(input.Buffer, input.StartIndex, count); input.ConsumeBytes(count); } } private void WriteLenNLen(ushort len, OutputBuffer output) { // len output.WriteUInt16(len); // nlen ushort onesComp = (ushort)(~(ushort)len); output.WriteUInt16(onesComp); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. namespace System.IO.Compression { using System.Diagnostics; internal class CopyEncoder { // padding for copy encoder formatting // - 1 byte for header // - 4 bytes for len, nlen private const int PaddingSize = 5; // max uncompressed deflate block size is 64K. private const int MaxUncompressedBlockSize = 65536; // null input means write an empty payload with formatting info. This is needed for the final block. public void GetBlock(DeflateInput input, OutputBuffer output, bool isFinal) { Debug.Assert(output != null); Debug.Assert(output.FreeBytes >= PaddingSize); // determine number of bytes to write int count = 0; if (input != null) { // allow space for padding and bits not yet flushed to buffer count = Math.Min(input.Count, output.FreeBytes - PaddingSize - output.BitsInBuffer); // we don't expect the output buffer to ever be this big (currently 4K), but we'll check this // just in case that changes. if (count > MaxUncompressedBlockSize - PaddingSize) { count = MaxUncompressedBlockSize - PaddingSize; } } // write header and flush bits if (isFinal) { output.WriteBits(FastEncoderStatics.BFinalNoCompressionHeaderBitCount, FastEncoderStatics.BFinalNoCompressionHeader); } else { output.WriteBits(FastEncoderStatics.NoCompressionHeaderBitCount, FastEncoderStatics.NoCompressionHeader); } // now we're aligned output.FlushBits(); // write len, nlen WriteLenNLen((ushort)count, output); // write uncompressed bytes if (input != null && count > 0) { output.WriteBytes(input.Buffer, input.StartIndex, count); input.ConsumeBytes(count); } } private void WriteLenNLen(ushort len, OutputBuffer output) { // len output.WriteUInt16(len); // nlen ushort onesComp = (ushort)(~(ushort)len); output.WriteUInt16(onesComp); } } } // 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
- CellRelation.cs
- GridViewRowPresenter.cs
- BasicAsyncResult.cs
- SubpageParaClient.cs
- EnumerableCollectionView.cs
- ListControl.cs
- DataGridCellsPanel.cs
- ImageIndexEditor.cs
- TextMarkerSource.cs
- ObservableDictionary.cs
- StrongNamePublicKeyBlob.cs
- Monitor.cs
- AnimationClock.cs
- LogicalExpressionTypeConverter.cs
- httpserverutility.cs
- OracleCommand.cs
- ComplexLine.cs
- PathData.cs
- FormatConvertedBitmap.cs
- CursorConverter.cs
- ListControlDataBindingHandler.cs
- WebUtility.cs
- RowVisual.cs
- BamlLocalizabilityResolver.cs
- CanonicalXml.cs
- CompositeActivityCodeGenerator.cs
- CreateParams.cs
- SafeLibraryHandle.cs
- AutomationPropertyInfo.cs
- RegisteredDisposeScript.cs
- RequestContext.cs
- InvokeProviderWrapper.cs
- ItemsPresenter.cs
- PostBackOptions.cs
- XmlSchemaProviderAttribute.cs
- hebrewshape.cs
- AssemblyBuilder.cs
- HttpAsyncResult.cs
- ArrayItemValue.cs
- ReadOnlyNameValueCollection.cs
- AnimationTimeline.cs
- SchemaEntity.cs
- HtmlButton.cs
- ObjectQuery.cs
- SpeakProgressEventArgs.cs
- SQLInt32.cs
- X509ChainPolicy.cs
- SqlDataSourceParameterParser.cs
- Gdiplus.cs
- ImageConverter.cs
- EntityClassGenerator.cs
- NTAccount.cs
- XmlDataImplementation.cs
- EncoderExceptionFallback.cs
- WebPartZone.cs
- Privilege.cs
- CustomUserNameSecurityTokenAuthenticator.cs
- OutOfMemoryException.cs
- OwnerDrawPropertyBag.cs
- ManagementQuery.cs
- SoapReflectionImporter.cs
- FilterQuery.cs
- ScriptManager.cs
- ContentPropertyAttribute.cs
- ParameterBuilder.cs
- Int16Converter.cs
- ListControl.cs
- Point4D.cs
- XPathSelectionIterator.cs
- ToolStripPanelRow.cs
- EntityDataSourceSelectedEventArgs.cs
- WebPartConnectionsEventArgs.cs
- CaseInsensitiveHashCodeProvider.cs
- Int16.cs
- basemetadatamappingvisitor.cs
- Hashtable.cs
- ElementHostAutomationPeer.cs
- ModelFactory.cs
- SqlDataSourceStatusEventArgs.cs
- COAUTHIDENTITY.cs
- CmsInterop.cs
- InitialServerConnectionReader.cs
- StrokeNodeOperations2.cs
- LinqDataSourceView.cs
- DisplayToken.cs
- ColorContext.cs
- SrgsRuleRef.cs
- BitSet.cs
- TreeNodeStyle.cs
- WorkflowCreationContext.cs
- XmlnsDefinitionAttribute.cs
- Focus.cs
- RectangleGeometry.cs
- KeyConverter.cs
- BitmapCacheBrush.cs
- FileUpload.cs
- DataTablePropertyDescriptor.cs
- Converter.cs
- nulltextnavigator.cs
- ScopedKnownTypes.cs