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
- Int32Converter.cs
- ToolStripSettings.cs
- OrthographicCamera.cs
- TabControlCancelEvent.cs
- HtmlInputPassword.cs
- XmlAttributeOverrides.cs
- UnsafeNativeMethods.cs
- EntityKey.cs
- ResumeStoryboard.cs
- Crc32.cs
- EventLogInformation.cs
- SoapIncludeAttribute.cs
- Internal.cs
- NullableDoubleAverageAggregationOperator.cs
- TabletCollection.cs
- ColumnBinding.cs
- UrlPath.cs
- GrammarBuilder.cs
- SocketSettings.cs
- OleTxTransaction.cs
- Message.cs
- SHA384Cng.cs
- AuthorizationRuleCollection.cs
- XMLUtil.cs
- CallbackDebugElement.cs
- ScriptingSectionGroup.cs
- ProviderManager.cs
- RuleRef.cs
- DbUpdateCommandTree.cs
- FileLogRecordStream.cs
- SmiSettersStream.cs
- ConfigXmlElement.cs
- CursorInteropHelper.cs
- xmlfixedPageInfo.cs
- _ConnectOverlappedAsyncResult.cs
- TreeNodeBindingCollection.cs
- Enum.cs
- GeometryConverter.cs
- DataGridViewCell.cs
- InheritanceContextHelper.cs
- TaskFileService.cs
- SelectorAutomationPeer.cs
- Transform3DGroup.cs
- LicenseContext.cs
- EntitySqlQueryCacheKey.cs
- HttpHandlersSection.cs
- ColorAnimation.cs
- GridItemCollection.cs
- InputProviderSite.cs
- WindowsStatic.cs
- FormatterConverter.cs
- ParseNumbers.cs
- RegexInterpreter.cs
- VisualTarget.cs
- RadioButtonBaseAdapter.cs
- XmlSchemaComplexContentRestriction.cs
- UnsafeNativeMethods.cs
- _NestedMultipleAsyncResult.cs
- WebFormsRootDesigner.cs
- TreeNodeClickEventArgs.cs
- FormatterServices.cs
- WebPartPersonalization.cs
- CryptographicAttribute.cs
- SaveFileDialog.cs
- EnterpriseServicesHelper.cs
- PointUtil.cs
- AudioSignalProblemOccurredEventArgs.cs
- Peer.cs
- DocumentsTrace.cs
- DrawingVisual.cs
- HtmlGenericControl.cs
- RegistryKey.cs
- PointCollectionValueSerializer.cs
- ThrowHelper.cs
- NumberSubstitution.cs
- RawStylusInputCustomData.cs
- ClockGroup.cs
- FixedSOMFixedBlock.cs
- DrawToolTipEventArgs.cs
- TableHeaderCell.cs
- RTTrackingProfile.cs
- XhtmlBasicLiteralTextAdapter.cs
- HtmlShim.cs
- StylusTip.cs
- ZipIOExtraFieldZip64Element.cs
- SecurityHeaderLayout.cs
- SqlUserDefinedAggregateAttribute.cs
- HTMLTextWriter.cs
- PolygonHotSpot.cs
- InitializerFacet.cs
- SkinIDTypeConverter.cs
- DataGridViewCellValueEventArgs.cs
- AssemblyAttributes.cs
- CustomValidator.cs
- Int32RectValueSerializer.cs
- latinshape.cs
- EventLogTraceListener.cs
- SortedList.cs
- BooleanKeyFrameCollection.cs
- pingexception.cs