本文整理汇总了C#中CompressionMode类的典型用法代码示例。如果您正苦于以下问题:C# CompressionMode类的具体用法?C# CompressionMode怎么用?C# CompressionMode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CompressionMode类属于命名空间,在下文中一共展示了CompressionMode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeflateStream
public DeflateStream(Stream stream, CompressionMode mode, bool leaveOpen)
{
if (stream == null)
throw new ArgumentNullException("stream");
switch (mode)
{
case CompressionMode.Decompress:
if (!stream.CanRead)
{
throw new ArgumentException(SR.NotReadableStream, "stream");
}
_inflater = CreateInflater();
break;
case CompressionMode.Compress:
if (!stream.CanWrite)
{
throw new ArgumentException(SR.NotWriteableStream, "stream");
}
_deflater = CreateDeflater(null);
break;
default:
throw new ArgumentException(SR.ArgumentOutOfRange_Enum, "mode");
}
_stream = stream;
_mode = mode;
_leaveOpen = leaveOpen;
_buffer = new byte[DefaultBufferSize];
}
示例2: LZ4NetStream
internal LZ4NetStream(Stream innerStream, CompressionMode compressionMode, bool leaveInnerStreamOpen,
LZ4Codec codec)
{
if (innerStream == null)
{
throw new ArgumentNullException(nameof(innerStream));
}
switch (compressionMode)
{
case CompressionMode.Compress:
case CompressionMode.Decompress:
break;
default:
throw new ArgumentOutOfRangeException(nameof(compressionMode));
}
if (codec == null)
{
throw new ArgumentNullException(nameof(codec));
}
this.innerStream = innerStream;
this.compressionMode = compressionMode;
this.leaveInnerStreamOpen = leaveInnerStreamOpen;
this.codec = codec;
}
示例3: TextureNative
public TextureNative(SectionHeader header, Stream stream)
: base(header, stream)
{
SectionHeader.Read(stream);
var reader = new BinaryReader(stream);
PlatformID = reader.ReadUInt32();
FilterFlags = (Filter) reader.ReadUInt16();
WrapV = (WrapMode) reader.ReadByte();
WrapU = (WrapMode) reader.ReadByte();
DiffuseName = reader.ReadString(32);
AlphaName = reader.ReadString(32);
Format = (RasterFormat) reader.ReadUInt32();
if (PlatformID == 9) {
var dxt = reader.ReadString(4);
switch (dxt) {
case "DXT1":
Compression = CompressionMode.DXT1;
break;
case "DXT3":
Compression = CompressionMode.DXT3; break;
default:
Compression = CompressionMode.None; break;
}
} else {
Alpha = reader.ReadUInt32() == 0x1;
}
Width = reader.ReadUInt16();
Height = reader.ReadUInt16();
BPP = (byte) (reader.ReadByte() >> 3);
MipMapCount = reader.ReadByte();
RasterType = reader.ReadByte();
if (RasterType != 0x4) {
throw new Exception("Unexpected RasterType, expected 0x04.");
}
if (PlatformID == 9) {
Alpha = (reader.ReadByte() & 0x1) == 0x1;
} else {
Compression = (CompressionMode) reader.ReadByte();
}
ImageDataSize = reader.ReadInt32();
ImageData = reader.ReadBytes(ImageDataSize);
if ((Format & RasterFormat.ExtMipMap) != 0) {
var tot = ImageDataSize;
for (var i = 0; i < MipMapCount; ++i) {
tot += ImageDataSize >> (2 * i);
}
ImageLevelData = reader.ReadBytes(tot);
} else {
ImageLevelData = ImageData;
}
}
示例4: SnappyStream
/// <summary>
/// Initializes a new instance of the <see cref="SnappyStream"/> class.
/// </summary>
/// <param name="s">The stream.</param>
/// <param name="mode">The compression mode.</param>
/// <param name="leaveOpen">If set to <c>true</c> leaves the stream open when complete.</param>
/// <param name="checksum"><c>true</c> if checksums should be written to the stream </param>
public SnappyStream(Stream s, CompressionMode mode, bool leaveOpen, bool checksum)
{
stream = s;
compressionMode = mode;
leaveStreamOpen = leaveOpen;
writeChecksums = checksum;
if (compressionMode == CompressionMode.Decompress)
{
if (!stream.CanRead)
throw new InvalidOperationException("Trying to decompress and underlying stream not readable.");
decompressor = new SnappyDecompressor();
CheckStreamIdentifier();
CheckStreamHeader();
}
if (compressionMode == CompressionMode.Compress)
{
if (!stream.CanWrite)
throw new InvalidOperationException("Trying to compress and underlying stream is not writable.");
compressor = new SnappyCompressor();
stream.WriteByte(StreamIdentifier);
stream.Write(StreamHeader, 0, StreamHeader.Length);
}
}
示例5: ZlibStreamConstructorTest
public void ZlibStreamConstructorTest()
{
Stream stream = null; // TODO: Initialize to an appropriate value
CompressionMode mode = new CompressionMode(); // TODO: Initialize to an appropriate value
ZlibStream target = new ZlibStream(stream, mode);
Assert.Inconclusive("TODO: Implement code to verify target");
}
示例6: BufferedDeflateStream
public BufferedDeflateStream( int bufferSize, Stream stream, CompressionMode mode, bool leaveOpen )
: base(stream, mode, leaveOpen)
{
buffer = new byte[ bufferSize ];
bSize = bufferSize;
bPtr = 0;
}
示例7: ZOutputStream
public ZOutputStream(Stream output, CompressionLevel level, bool nowrap)
: this()
{
this._output = output;
this._compressor = new Deflate(level, nowrap);
this._compressionMode = CompressionMode.Compress;
}
示例8: DeflateStream
internal DeflateStream(Stream stream, CompressionMode mode, bool leaveOpen, bool usingGZip){
_stream = stream;
_mode = mode;
_leaveOpen = leaveOpen;
if(_stream == null ) {
throw new ArgumentNullException("stream");
}
switch (_mode) {
case CompressionMode.Decompress:
if (!(_stream.CanRead)) {
throw new ArgumentException(SR.GetString(SR.NotReadableStream), "stream");
}
inflater = new Inflater(usingGZip);
m_CallBack = new AsyncCallback(ReadCallback);
break;
case CompressionMode.Compress:
if (!(_stream.CanWrite)) {
throw new ArgumentException(SR.GetString(SR.NotWriteableStream), "stream");
}
deflater = new Deflater(usingGZip);
m_AsyncWriterDelegate = new AsyncWriteDelegate(this.InternalWrite);
m_CallBack = new AsyncCallback(WriteCallback);
break;
default:
throw new ArgumentException(SR.GetString(SR.ArgumentOutOfRange_Enum), "mode");
}
buffer = new byte[bufferSize];
}
示例9: DeflateStream
internal DeflateStream(Stream stream, CompressionMode mode, bool leaveOpen, bool usingGZip)
{
this._stream = stream;
this._mode = mode;
this._leaveOpen = leaveOpen;
if (this._stream == null) {
throw new ArgumentNullException("stream");
}
switch (this._mode) {
case CompressionMode.Decompress:
if (!this._stream.CanRead) {
throw new ArgumentException("The base stream is not readable.", "stream");
}
this.inflater = new Inflater(usingGZip);
this.m_CallBack = new AsyncCallback(this.ReadCallback);
break;
case CompressionMode.Compress:
if (!this._stream.CanWrite) {
throw new ArgumentException("The base stream is not writeable.", "stream");
}
this.deflater = new Deflater(usingGZip);
this.m_AsyncWriterDelegate = new AsyncWriteDelegate(this.InternalWrite);
this.m_CallBack = new AsyncCallback(this.WriteCallback);
break;
default:
throw new ArgumentException("Enum value was out of legal range.", "mode");
}
this.buffer = new byte[0x1000];
}
示例10: toCompressStream
/// <summary>
/// 根据压缩类型获取压缩数据流
/// </summary>
/// <param name="dataStream">原始数据流</param>
/// <param name="mode">压缩模式</param>
/// <param name="leaveOpen">是否流保留为打开状态</param>
/// <param name="type">压缩类型</param>
/// <returns>数据流</returns>
private static Stream toCompressStream(this Stream dataStream, CompressionMode mode, bool leaveOpen, compression type)
{
Stream stream = dataStream;
if (type == compression.GZip) stream = (Stream)new GZipStream(dataStream, mode, leaveOpen);
else stream = (Stream)new DeflateStream(dataStream, mode, leaveOpen);
return stream;
}
示例11: DeflateStream
public DeflateStream(Stream stream, CompressionMode mode, bool leaveOpen)
{
this._stream = stream;
this._mode = mode;
this._leaveOpen = leaveOpen;
if (this._stream == null)
{
throw new ArgumentNullException("stream");
}
switch (this._mode)
{
case CompressionMode.Decompress:
if (!this._stream.CanRead)
{
throw new ArgumentException(SR.GetString("NotReadableStream"), "stream");
}
this.inflater = new Inflater();
this.m_CallBack = new AsyncCallback(this.ReadCallback);
break;
case CompressionMode.Compress:
if (!this._stream.CanWrite)
{
throw new ArgumentException(SR.GetString("NotWriteableStream"), "stream");
}
this.deflater = new Deflater();
this.m_AsyncWriterDelegate = new AsyncWriteDelegate(this.InternalWrite);
this.m_CallBack = new AsyncCallback(this.WriteCallback);
break;
default:
throw new ArgumentException(SR.GetString("ArgumentOutOfRange_Enum"), "mode");
}
this.buffer = new byte[0x1000];
}
示例12: DeflateStream
internal DeflateStream (Stream compressedStream, CompressionMode mode, bool leaveOpen, bool gzip) {
if (compressedStream == null)
throw new ArgumentNullException ("compressedStream");
switch (mode) {
case CompressionMode.Compress:
if (!compressedStream.CanWrite)
throw new ArgumentException ("The base stream is not writeable.");
OutputStream outStream = new OutputStreamImpl(compressedStream);
_writer = gzip ? new GZIPOutputStream (outStream) : new DeflaterOutputStream (outStream, new Deflater (Deflater.DEFAULT_COMPRESSION, true));
break;
case CompressionMode.Decompress:
if (!compressedStream.CanRead)
throw new ArgumentException ("The base stream is not readable.");
InputStream inStream = new InputStreamImpl (compressedStream);
_reader = gzip ? new GZIPInputStream (inStream) : new InflaterInputStream (inStream, new Inflater (true));
break;
default:
throw new ArgumentException ("mode");
}
_baseStream = compressedStream;
_leaveOpen = leaveOpen;
_open = true;
}
示例13: zlibDeflate
public static void zlibDeflate(
string pathInput,
string pathOutput,
CompressionMode mode,
CompressionLevel level
)
{
using (Stream input = File.OpenRead(pathInput))
using (Stream output = File.Create(pathOutput))
using (Stream deflateStream = new DeflateStream(
mode == CompressionMode.Compress ? output : input,
mode, level, true))
{
byte[] buff = new byte[ZLIB_BUFF_SIZE];
int n = 0;
Stream toRead = mode == CompressionMode.Compress ?
input : deflateStream;
Stream toWrite = mode == CompressionMode.Compress ?
deflateStream : output;
while (0 != (n = toRead.Read(buff, 0, buff.Length)))
{
toWrite.Write(buff, 0, n);
}
deflateStream.Close();
input.Close();
output.Close();
}
}
示例14: ZlibBaseStream
public ZlibBaseStream(System.IO.Stream stream,
CompressionMode compressionMode,
CompressionLevel level,
ZlibStreamFlavor flavor,
bool leaveOpen)
:this(stream, compressionMode, level, flavor,leaveOpen, ZlibConstants.WindowBitsDefault)
{ }
示例15: CompressedStream
/// <summary>
///
/// </summary>
/// <param name="contentEncoding"></param>
/// <param name="stream"></param>
/// <param name="mode"></param>
public CompressedStream(string contentEncoding, Stream stream, CompressionMode mode)
{
if (contentEncoding.IndexOf(_contentIsGZipToken, StringComparison.InvariantCultureIgnoreCase) != -1)
_gzipStream = new GZipStream(stream, mode);
else if (contentEncoding != null && contentEncoding.IndexOf(_contentIsDeflateToken, StringComparison.InvariantCultureIgnoreCase) != -1)
_deflateStream = new DeflateStream(stream, mode);
}