本文整理汇总了C#中CompressionType类的典型用法代码示例。如果您正苦于以下问题:C# CompressionType类的具体用法?C# CompressionType怎么用?C# CompressionType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CompressionType类属于命名空间,在下文中一共展示了CompressionType类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CompressBytes
public static byte[] CompressBytes(CompressionType type, byte[] fileBytes)
{
MemoryStream ms = new MemoryStream();
Stream compressedStream = null;
if (type == CompressionType.deflate)
{
compressedStream = new DeflateStream(ms, CompressionMode.Compress, true);
}
else if (type == CompressionType.gzip)
{
compressedStream = new GZipStream(ms, CompressionMode.Compress, true);
}
if (type != CompressionType.none)
{
//write the bytes to the compressed stream
compressedStream.Write(fileBytes, 0, fileBytes.Length);
compressedStream.Close();
byte[] output = ms.ToArray();
ms.Close();
return output;
}
//not compressed
return fileBytes;
}
开发者ID:VegasoftTI,项目名称:Dnn.Platform,代码行数:27,代码来源:SimpleCompressor.cs
示例2: SetMaxSize
private static void SetMaxSize(CompressionType compression, ImporterSettings settings)
{
switch (compression)
{
case CompressionType.Dxt:
case CompressionType.Dxt1:
case CompressionType.Dxt5:
case CompressionType.ShelfHeroshot:
case CompressionType.ShelfHeroshotBlackWhite:
settings.MaxSize = 1024;
break;
case CompressionType.Dxt_2K:
case CompressionType.Dxt1_2K:
case CompressionType.Dxt5_2K:
case CompressionType.NoesisLifestyleFeatures:
case CompressionType.FilterTest:
settings.MaxSize = 1024*2;
break;
case CompressionType.Thumbnail140:
case CompressionType.Thumbnail256:
settings.MaxSize = 256;
break;
default:
settings.MaxSize = 1024*2;
break;
}
}
开发者ID:herbchow,项目名称:AssetBundler,代码行数:27,代码来源:CompressionSettings.cs
示例3: RequestImage
public void RequestImage(ImageType img_type, CompressionType comp_type = CompressionType.LZ4)
{
byte[] send_params = new byte[2];
switch (comp_type)
{
case CompressionType.Uncompressed:
send_params[0] = COMPR_TYPE_NONE;
break;
case CompressionType.LZ4:
send_params[0] = COMPR_TYPE_LZ4;
break;
default:
break;
}
switch (img_type)
{
case ImageType.Depth:
send_params[1] = IMG_TYPE_DEPTH;
break;
case ImageType.Image:
send_params[1] = IMG_TYPE_IMAGE;
break;
case ImageType.IR:
send_params[1] = IMG_TYPE_IR;
break;
default:
break;
}
sock.Send(send_params);
buf = sock.Recv();
switch (comp_type)
{
case CompressionType.Uncompressed:
buf.CopyTo(decompressed, 0);
break;
case CompressionType.LZ4:
dcmp.DecompressKnownSize(buf, decompressed, 640 * 480 * (img_type == ImageType.Depth ? depth_bpp : (img_type == ImageType.Image ? image_bpp : ir_bpp)));
break;
default:
break;
}
bmp_d = bmp.LockBits(new Rectangle(0, 0, 640, 480), ImageLockMode.WriteOnly,
(img_type == ImageType.Depth ? PixelFormat.Format16bppRgb555 : (img_type == ImageType.Image ? PixelFormat.Format24bppRgb : PixelFormat.Format8bppIndexed)));
// http://msdn.microsoft.com/en-us/library/system.drawing.imaging.bitmapdata.aspx
IntPtr ptr = bmp_d.Scan0;
// Copy the RGB values back to the bitmap
System.Runtime.InteropServices.Marshal.Copy(decompressed, 0, ptr, bmp_d.Width * bmp_d.Height * (img_type == ImageType.Depth ? depth_bpp : (img_type == ImageType.Image ? image_bpp : ir_bpp))); // elvileg mindenképp 640x480x2, fixme
// Unlock the bits.
bmp.UnlockBits(bmp_d);
// elvileg ez a leggyorsabb mód a másolásra, ennél gyorsabban nem lehet...
}
开发者ID:andor44,项目名称:ksclient,代码行数:60,代码来源:Client.cs
示例4: ZipEntry
internal ZipEntry(Stream fileStream, string entryName, CompressionType compressionType)
: this(entryName, compressionType)
{
if (!fileStream.CanRead) throw new IOException("Can not read from file stream");
_fileStream = fileStream;
IsDirty = true;
}
开发者ID:sanjayasl,项目名称:custom-rom-creator-studio,代码行数:7,代码来源:ZipEntry.cs
示例5: UglyStream
/// <summary>
/// Constructor
/// </summary>
/// <param name="StreamUsing">The stream for the page</param>
/// <param name="Compression">The compression we're using (gzip or deflate)</param>
/// <param name="Type">Minification type to use (defaults to HTML)</param>
public UglyStream(Stream StreamUsing, CompressionType Compression, MinificationType Type = MinificationType.HTML)
: base()
{
this.Compression = Compression;
this.StreamUsing = StreamUsing;
this.Type = Type;
}
开发者ID:Adilson,项目名称:Craig-s-Utility-Library,代码行数:13,代码来源:UglyStream.cs
示例6: NetworkUpdateWorld
void NetworkUpdateWorld(byte[] data)
{
World world = (World)FindObjectOfType(typeof(World));
world.loadDefaultWorld();
string size = "";
CompressionType compression;
using (MemoryStream stream = new MemoryStream(data))
{
using (WorldInputStream reader = new WorldInputStream(stream))
{
reader.Read(world);
size = stream.Length.GetSizeReadable();
compression = reader.compressionType;
}
}
UnityEngine.Debug.Log("world received (" + size + " | " + compression + ")");
GameObject player = GameObject.FindWithTag("Player");
if (player)
player.SendMessage("Respawn");
CircularObjectPool.instance.RecallAllObjectsForType("Debris");
}
开发者ID:silantzis,项目名称:blockotron,代码行数:27,代码来源:NetworkWorldSynchronizer.cs
示例7: Test_Compress
// File : Create new, Append to existing, Raz existing
// ArchiveType : Rar = 0, Zip = 1, Tar = 2, SevenZip = 3, GZip = 4
// CompressionType : None = 0, GZip = 1, BZip2 = 2, PPMd = 3, Deflate = 4, Rar = 5, LZMA = 6, BCJ = 7, BCJ2 = 8, Unknown = 9,
// Zip compression type : BZip2
// GZip compression type : GZip
// example from https://github.com/adamhathcock/sharpcompress/wiki/API-Examples
// this example dont work to add file to an existing zip
public static void Test_Compress(string compressFile, IEnumerable<string> files, string baseDirectory = null, ArchiveType archiveType = ArchiveType.Zip,
CompressionType compressionType = CompressionType.BZip2, CompressionLevel compressionLevel = CompressionLevel.Default)
{
//FileOption
if (baseDirectory != null && !baseDirectory.EndsWith("\\"))
baseDirectory = baseDirectory + "\\";
CompressionInfo compressionInfo = new CompressionInfo();
compressionInfo.DeflateCompressionLevel = compressionLevel;
compressionInfo.Type = compressionType;
//Trace.WriteLine("SharpCompressManager : DeflateCompressionLevel {0}", compressionInfo.DeflateCompressionLevel);
//Trace.WriteLine("SharpCompressManager : CompressionType {0}", compressionInfo.Type);
Trace.WriteLine($"open compressed file \"{compressFile}\"");
// File.OpenWrite ==> OpenOrCreate
using (FileStream stream = File.OpenWrite(compressFile))
using (IWriter writer = WriterFactory.Open(stream, archiveType, compressionInfo))
//using (IWriter writer = WriterFactory.Open(stream, archiveType, CompressionType.BZip2))
{
foreach (string file in files)
{
string entryPath;
if (baseDirectory != null && file.StartsWith(baseDirectory))
entryPath = file.Substring(baseDirectory.Length);
else
entryPath = zPath.GetFileName(file);
Trace.WriteLine($"add file \"{entryPath}\" \"{file}\"");
writer.Write(entryPath, file);
}
}
}
开发者ID:labeuze,项目名称:source,代码行数:38,代码来源:Test_SharpCompressManager.cs
示例8: ArchiveStreamReadExtractAll
protected void ArchiveStreamReadExtractAll(IEnumerable<string> testArchives, CompressionType compression)
{
foreach (var path in testArchives)
{
ResetScratch();
using (Stream stream = File.OpenRead(path))
using (var archive = ArchiveFactory.Open(stream))
{
Assert.IsTrue(archive.IsSolid);
using (var reader = archive.ExtractAllEntries())
{
ReaderTests.UseReader(this, reader, compression);
}
VerifyFiles();
if (archive.Entries.First().CompressionType == CompressionType.Rar)
{
return;
}
foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
{
entry.WriteToDirectory(SCRATCH_FILES_PATH,
ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite);
}
}
VerifyFiles();
}
}
开发者ID:fx02,项目名称:sharpcompress,代码行数:28,代码来源:ArchiveTests.cs
示例9: ImaqFlatten
public static RawData ImaqFlatten(Image image, FlattenType type, CompressionType compression, int quality)
{
uint size = 0;
IntPtr rv = Interop.imaqFlatten(image.NativeObj, type, compression, quality, ref size);
return new RawData(rv, size, true);
}
开发者ID:chopshop-166,项目名称:WPILib,代码行数:7,代码来源:PublicMethods.cs
示例10: UnCompress
private static byte[] UnCompress(this byte[] bytes, CompressionType type)
{
if (bytes == null || bytes.Length == 0)
return new byte[0];
using (var stream = type == CompressionType.GZip
? (Stream)new GZipStream(new MemoryStream(bytes), CompressionMode.Decompress)
: new DeflateStream(new MemoryStream(bytes), CompressionMode.Decompress))
{
var buffer = new byte[4096];
using (var memory = new MemoryStream())
{
int count;
do
{
count = stream.Read(buffer, 0, buffer.Length);
if (count > 0)
{
memory.Write(buffer, 0, count);
}
}
while (count > 0);
bytes = memory.ToArray();
}
}
return bytes;
}
开发者ID:jozsurf,项目名称:combres,代码行数:26,代码来源:CompressionExtensions.cs
示例11: Open
public static IWriter Open(Stream stream, ArchiveType archiveType, CompressionType compressionType, bool leaveOpen = false)
{
return Open(stream, archiveType, new CompressionInfo
{
Type = compressionType
}, leaveOpen);
}
开发者ID:weltkante,项目名称:sharpcompress,代码行数:7,代码来源:WriterFactory.cs
示例12: Open
public static IWriter Open(Stream stream, ArchiveType archiveType, CompressionType compressionType)
{
return Open(stream, archiveType, new CompressionInfo
{
Type = compressionType
});
}
开发者ID:nickchal,项目名称:pash,代码行数:7,代码来源:WriterFactory.cs
示例13: CompressAsync
public static async Task<Stream> CompressAsync(CompressionType type, Stream original)
{
using (var ms = new MemoryStream())
{
Stream compressedStream = null;
if (type == CompressionType.deflate)
{
compressedStream = new DeflateStream(ms, CompressionMode.Compress);
}
else if (type == CompressionType.gzip)
{
compressedStream = new GZipStream(ms, CompressionMode.Compress);
}
if (type != CompressionType.none)
{
using (compressedStream)
{
await original.CopyToAsync(compressedStream);
}
//NOTE: If we just try to return the ms instance, it will simply not work
// a new stream needs to be returned that contains the compressed bytes.
// I've tried every combo and this appears to be the only thing that works.
byte[] output = ms.ToArray();
return new MemoryStream(ms.ToArray());
}
//not compressed
return original;
}
}
开发者ID:eByte23,项目名称:Smidge,代码行数:34,代码来源:Compressor.cs
示例14: Close
public void Close()
{
if (Map != null) { Map.Dispose(); Map = null; }
Address = null;
Length = 0;
Compression = CompressionType.None;
}
开发者ID:blahblahblahblah831,项目名称:brawltools2,代码行数:7,代码来源:ResourceNode.cs
示例15: Decompress
public static byte[] Decompress(string file, CompressionType cmp)
{
byte[] ret = new byte[0];
switch (cmp)
{
case CompressionType.Uncompressed:
ret = File.ReadAllBytes(file);
break;
case CompressionType.Kosinski:
ret = Kosinski.Decompress(file);
break;
case CompressionType.KosinskiM:
ret = ModuledKosinski.Decompress(file, LevelData.littleendian ? Endianness.LittleEndian : Endianness.BigEndian);
break;
case CompressionType.Nemesis:
ret = Nemesis.Decompress(file);
break;
case CompressionType.Enigma:
ret = Enigma.Decompress(file, LevelData.littleendian ? Endianness.LittleEndian : Endianness.BigEndian);
break;
case CompressionType.SZDD:
ret = SZDDComp.SZDDComp.Decompress(file);
break;
default:
break;
}
return ret;
}
开发者ID:OurSonic,项目名称:Sonic-Image-Parser,代码行数:28,代码来源:Compression.cs
示例16: DataSource
public DataSource(FileMap map, CompressionType compression)
{
Address = map.Address;
Length = map.Length;
Map = map;
Compression = compression;
}
开发者ID:blahblahblahblah831,项目名称:brawltools2,代码行数:7,代码来源:ResourceNode.cs
示例17: CompressText
/// <summary>
/// Compressor that takes the <paramref name="text"/> and puts it in the <paramref name="outputStream"/> in a compressed format
/// </summary>
/// <param name="outputStream">Stream to write the compressed value to</param>
/// <param name="text">Text to compress</param>
/// <param name="encoding">Encoding to be used when compressing</param>
/// <param name="compressionType">Type of compression to be used when compressing</param>
public void CompressText(Stream outputStream, string text, Encoding encoding, CompressionType compressionType)
{
this.logger?.LogDebug($"Compressing the following text with the '{compressionType}' format: {text}");
switch (compressionType)
{
case CompressionType.Gzip:
using (GZipStream gZipStream = new GZipStream(outputStream, CompressionMode.Compress))
{
using (StreamWriter streamWriter = new StreamWriter(gZipStream))
{
streamWriter.Write(text);
streamWriter.Flush();
}
}
break;
case CompressionType.Deflate:
using (DeflateStream deflateStream = new DeflateStream(outputStream, CompressionMode.Compress))
{
using (StreamWriter streamWriter = new StreamWriter(deflateStream))
{
streamWriter.Write(text);
streamWriter.Flush();
}
}
break;
default:
throw new ArgumentOutOfRangeException(nameof(compressionType), compressionType, null);
}
this.logger?.LogDebug("Compression successful");
}
开发者ID:edjCase,项目名称:JsonRpc,代码行数:37,代码来源:DefaultRpcCompressor.cs
示例18: DecompressBytes
public static byte[] DecompressBytes(CompressionType type, byte[] compressedBytes)
{
using (var ms = new MemoryStream())
{
Stream decompressedStream = null;
if (type == CompressionType.deflate)
{
decompressedStream = new DeflateStream(ms, CompressionMode.Decompress, true);
}
else if (type == CompressionType.gzip)
{
decompressedStream = new GZipStream(ms, CompressionMode.Decompress, true);
}
if (type != CompressionType.none)
{
//write the bytes to the compressed stream
decompressedStream.Write(compressedBytes, 0, compressedBytes.Length);
decompressedStream.Close();
byte[] output = ms.ToArray();
ms.Close();
return output;
}
//not compressed
return compressedBytes;
}
}
开发者ID:dufkaf,项目名称:ClientDependency,代码行数:30,代码来源:SimpleCompressor.cs
示例19: GetDataInputStream
public virtual Stream GetDataInputStream(CompressionType compression)
{
try {
switch (compression)
{
case CompressionType.None:
using (FileStream fstr = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
long length = fstr.Seek(0, SeekOrigin.End);
fstr.Seek(0, SeekOrigin.Begin);
byte[] data = new byte[length];
fstr.Read(data, 0, data.Length);
return new MemoryStream(data);
}
case CompressionType.GZip:
Stream stream1 = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
return new GZipStream(stream1, CompressionMode.Decompress);
case CompressionType.Zlib:
Stream stream2 = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
return new ZlibStream(stream2, CompressionMode.Decompress);
case CompressionType.Deflate:
Stream stream3 = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
return new DeflateStream(stream3, CompressionMode.Decompress);
default:
throw new ArgumentException("Invalid CompressionType specified", "compression");
}
}
catch (Exception ex) {
throw new NbtIOException("Failed to open compressed NBT data stream for input.", ex);
}
}
开发者ID:omglolbah,项目名称:Blightfall,代码行数:33,代码来源:NBTFile.cs
示例20: SaveTo
public static void SaveTo(this IWritableArchive writableArchive,
FileInfo fileInfo, CompressionType compressionType)
{
using (var stream = fileInfo.Open(FileMode.Create, FileAccess.Write))
{
writableArchive.SaveTo(stream, new CompressionInfo {Type = compressionType});
}
}
开发者ID:kouseki926,项目名称:sharpcompress,代码行数:8,代码来源:IWritableArchive.Extensions.cs
注:本文中的CompressionType类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论