Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- BaseDataBoundControl.cs
- HttpCapabilitiesSectionHandler.cs
- WebPartMenu.cs
- StreamSecurityUpgradeAcceptor.cs
- InternalConfigRoot.cs
- DynamicEntity.cs
- FreezableOperations.cs
- Currency.cs
- SiteMapDataSourceDesigner.cs
- IdentifierService.cs
- XmlSerializationWriter.cs
- PageThemeParser.cs
- OracleParameterBinding.cs
- AtomMaterializerLog.cs
- ObjectListComponentEditor.cs
- SyncOperationState.cs
- Message.cs
- MenuBase.cs
- PageEventArgs.cs
- DocumentPageTextView.cs
- _BufferOffsetSize.cs
- RoleManagerModule.cs
- LinearGradientBrush.cs
- ExpressionNode.cs
- NetworkInterface.cs
- ErrorReporting.cs
- SecurityManager.cs
- CommonObjectSecurity.cs
- ActiveXHost.cs
- WebEvents.cs
- DbProviderFactoriesConfigurationHandler.cs
- Attributes.cs
- DefaultTextStore.cs
- DbDataSourceEnumerator.cs
- EntityContainer.cs
- OleDbFactory.cs
- CompilerGeneratedAttribute.cs
- ProcessInputEventArgs.cs
- ImpersonateTokenRef.cs
- ListViewTableRow.cs
- DataColumn.cs
- JpegBitmapDecoder.cs
- MetafileHeaderWmf.cs
- UserControlBuildProvider.cs
- Interlocked.cs
- SecurityException.cs
- ControlBuilderAttribute.cs
- LinearGradientBrush.cs
- DBPropSet.cs
- DetailsViewPageEventArgs.cs
- FlatButtonAppearance.cs
- OleDbStruct.cs
- EntityDataSourceViewSchema.cs
- VisualCollection.cs
- SingleAnimationBase.cs
- SspiHelper.cs
- SetMemberBinder.cs
- ContractCodeDomInfo.cs
- _NestedSingleAsyncResult.cs
- InfoCardProofToken.cs
- MessageBox.cs
- ApplicationManager.cs
- SafeArchiveContext.cs
- OleDbParameterCollection.cs
- FixedPageStructure.cs
- StringReader.cs
- BamlTreeUpdater.cs
- OutOfProcStateClientManager.cs
- ProxyWebPartManager.cs
- GenericEnumConverter.cs
- ScrollProperties.cs
- OdbcReferenceCollection.cs
- KeyFrames.cs
- PostBackOptions.cs
- ToolStripDropDownClosingEventArgs.cs
- ReceiveActivityValidator.cs
- MatchAttribute.cs
- TakeOrSkipWhileQueryOperator.cs
- DesignerForm.cs
- hebrewshape.cs
- WebHttpEndpoint.cs
- PointCollection.cs
- _ListenerAsyncResult.cs
- UInt32.cs
- DataMisalignedException.cs
- ConnectionsZone.cs
- BasePropertyDescriptor.cs
- ControlCollection.cs
- Quaternion.cs
- FunctionCommandText.cs
- ConstantSlot.cs
- Setter.cs
- IDReferencePropertyAttribute.cs
- LicenseProviderAttribute.cs
- AsyncPostBackErrorEventArgs.cs
- SettingsBase.cs
- FontStretchConverter.cs
- DataGridViewCellStyleChangedEventArgs.cs
- CombinedGeometry.cs
- HttpCacheVary.cs