本文整理汇总了C#中CompressionMethod类的典型用法代码示例。如果您正苦于以下问题:C# CompressionMethod类的具体用法?C# CompressionMethod怎么用?C# CompressionMethod使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CompressionMethod类属于命名空间,在下文中一共展示了CompressionMethod类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ZipEntry
public ZipEntry(ZipEntry entry)
{
_externalFileAttributes = -1;
_method = CompressionMethod.Deflated;
ZipFileIndex = -1L;
if (entry == null)
{
throw new ArgumentNullException(nameof(entry));
}
_known = entry._known;
Name = entry.Name;
_size = entry._size;
_compressedSize = entry._compressedSize;
_crc = entry._crc;
_dosTime = entry._dosTime;
_method = entry._method;
_comment = entry._comment;
_versionToExtract = entry._versionToExtract;
_versionMadeBy = entry._versionMadeBy;
_externalFileAttributes = entry._externalFileAttributes;
Flags = entry.Flags;
ZipFileIndex = entry.ZipFileIndex;
Offset = entry.Offset;
_forceZip64 = entry._forceZip64;
if (entry._extra != null)
{
_extra = new byte[entry._extra.Length];
Array.Copy(entry._extra, 0, _extra, 0, entry._extra.Length);
}
}
示例2: Compress
public void Compress(string sourceFilename, string targetFilename, FileMode fileMode, OutArchiveFormat archiveFormat,
CompressionMethod compressionMethod, CompressionLevel compressionLevel, ZipEncryptionMethod zipEncryptionMethod,
string password, int bufferSize, int preallocationPercent, bool check, Dictionary<string, string> customParameters)
{
bufferSize *= this._sectorSize;
SevenZipCompressor compressor = new SevenZipCompressor();
compressor.FastCompression = true;
compressor.ArchiveFormat = archiveFormat;
compressor.CompressionMethod = compressionMethod;
compressor.CompressionLevel = compressionLevel;
compressor.DefaultItemName = Path.GetFileName(sourceFilename);
compressor.DirectoryStructure = false;
compressor.ZipEncryptionMethod = zipEncryptionMethod;
foreach (var pair in customParameters)
{
compressor.CustomParameters[pair.Key] = pair.Value;
}
using (FileStream sourceFileStream = new FileStream(sourceFilename,
FileMode.Open, FileAccess.Read, FileShare.None, bufferSize,
Win32.FileFlagNoBuffering | FileOptions.SequentialScan))
{
using (FileStream targetFileStream = new FileStream(targetFilename,
fileMode, FileAccess.ReadWrite, FileShare.ReadWrite, 8,
FileOptions.WriteThrough | Win32.FileFlagNoBuffering))
{
this.Compress(compressor, sourceFileStream, targetFileStream,
password, preallocationPercent, check, bufferSize);
}
}
}
示例3: RuntimeInfo
public RuntimeInfo(CompressionMethod method, int compressionLevel,
int size, string password, bool getCrc)
{
this.method = method;
this.compressionLevel = compressionLevel;
this.password = password;
this.size = size;
this.random = false;
original = new byte[Size];
if (random) {
System.Random rnd = new Random();
rnd.NextBytes(original);
}
else {
for (int i = 0; i < size; ++i) {
original[i] = (byte)'A';
}
}
if (getCrc) {
Crc32 crc32 = new Crc32();
crc32.Update(original, 0, size);
crc = crc32.Value;
}
}
示例4: CsvFile
public CsvFile(Stream stream, DataFileMode fileMode, CompressionMethod compression, Encoding encoding, CultureInfo culture)
: base(stream, fileMode, compression, encoding, culture)
{
InitializeMembers();
Open();
}
示例5: ZipEntry
public ZipEntry(ZipEntry entry)
{
externalFileAttributes = -1;
method = CompressionMethod.Deflated;
zipFileIndex = -1L;
if (entry == null)
{
throw new ArgumentNullException("entry");
}
known = entry.known;
name = entry.name;
size = entry.size;
compressedSize = entry.compressedSize;
crc = entry.crc;
dosTime = entry.dosTime;
method = entry.method;
comment = entry.comment;
versionToExtract = entry.versionToExtract;
versionMadeBy = entry.versionMadeBy;
externalFileAttributes = entry.externalFileAttributes;
flags = entry.flags;
zipFileIndex = entry.zipFileIndex;
offset = entry.offset;
forceZip64_ = entry.forceZip64_;
if (entry.extra != null)
{
extra = new byte[entry.extra.Length];
Array.Copy(entry.extra, 0, extra, 0, entry.extra.Length);
}
}
示例6: FormattedDataFile
protected FormattedDataFile(Stream stream, DataFileMode fileMode, CompressionMethod compression, Encoding encoding, CultureInfo culture)
: base(stream, fileMode, compression)
{
InitializeMembers();
this.encoding = encoding;
this.culture = culture;
}
示例7: ServerHello
public ServerHello(ProtocolVersion ver, byte[] random, byte[] sessionID, CipherSuite suite, CompressionMethod compression, Extension[] extensions)
: base(HandshakeType.ServerHello)
{
_version = ver;
_random = random;
_sessionID = sessionID;
_cipherSuite = suite;
_compression = compression;
_extensions = extensions;
}
示例8: SupportsMethod
/// <summary>
/// Is the given compression method/algrithm supported?
/// </summary>
/// <param name="method"> </param>
/// <returns> </returns>
public bool SupportsMethod(CompressionMethod method)
{
ElementList nList = SelectElements(typeof (Method));
foreach (Method m in nList)
{
if (m.CompressionMethod == method)
return true;
}
return false;
}
示例9: Ihdr
public Ihdr(UInt32 width, UInt32 height, BitDepth bitDepth, ColorType colorType, CompressionMethod compressionMethod = CompressionMethod.Default, FilterMethod filterMethod = FilterMethod.Default, InterlaceMethod interlaceMethod = InterlaceMethod.None)
: base(ChunkType.IHDR)
{
#region Sanity
if(width == 0 || width > Int32.MaxValue)
throw new ArgumentOutOfRangeException("width", "width must be greater than 0 and smaller than In32.MaxValue(2^31-1)");
if(height == 0 || height > Int32.MaxValue)
throw new ArgumentOutOfRangeException("height", "height must be greater than 0 and smaller than In32.MaxValue(2^31-1)");
BitDepth[] allowedBitDepths;
switch (colorType)
{
case ColorType.Grayscale:
if(!(allowedBitDepths = new[] { BitDepth._1, BitDepth._2, BitDepth._4, BitDepth._8, BitDepth._16 }).Contains(bitDepth))
throw new ArgumentOutOfRangeException("bitDepth", String.Format("bitDepth must be one of {0} for colorType {1}", allowedBitDepths.Aggregate("", (s, bd) => s + bd + ", ", s => s.Trim().Substring(0, s.Length - 2)), colorType));
break;
case ColorType.Rgb:
if(!(allowedBitDepths = new[]{BitDepth._8, BitDepth._16}).Contains(bitDepth))
throw new ArgumentOutOfRangeException("bitDepth", String.Format("bitDepth must be one of {0} for colorType {1}", allowedBitDepths.Aggregate("", (s, bd) => s + bd + ", ", s => s.Trim().Substring(0, s.Length - 2)), colorType));
break;
case ColorType.Palette:
if(!(allowedBitDepths = new[] { BitDepth._1, BitDepth._2, BitDepth._4, BitDepth._8}).Contains(bitDepth))
throw new ArgumentOutOfRangeException("bitDepth", String.Format("bitDepth must be one of {0} for colorType {1}", allowedBitDepths.Aggregate("", (s, bd) => s + bd + ", ", s => s.Trim().Substring(0, s.Length - 2)), colorType));
break;
case ColorType.GrayscaleWithAlpha:
if(!(allowedBitDepths = new[] { BitDepth._8, BitDepth._16}).Contains(bitDepth))
throw new ArgumentOutOfRangeException("bitDepth", String.Format("bitDepth must be one of {0} for colorType {1}", allowedBitDepths.Aggregate("", (s, bd) => s + bd + ", ", s => s.Trim().Substring(0, s.Length - 2)), colorType));
break;
case ColorType.Rgba:
if(!(allowedBitDepths = new[] { BitDepth._8, BitDepth._16}).Contains(bitDepth))
throw new ArgumentOutOfRangeException("bitDepth", String.Format("bitDepth must be one of {0} for colorType {1}", allowedBitDepths.Aggregate("", (s, bd) => s + bd + ", ", s => s.Trim().Substring(0, s.Length - 2)), colorType));
break;
default:
throw new ArgumentOutOfRangeException("colorType", String.Format("Unknown colorType: {0}", colorType));
}
if(compressionMethod != CompressionMethod.Default)
throw new ArgumentOutOfRangeException("compressionMethod", String.Format("Unknown compressionMethod: {0}", compressionMethod));
if(filterMethod != FilterMethod.Default)
throw new ArgumentOutOfRangeException("filterMethod", String.Format("Unknown filterMethod: {0}", filterMethod));
var allowedInterlaceMethods = new[] {InterlaceMethod.None, InterlaceMethod.Adam7};
if(!allowedInterlaceMethods.Contains(interlaceMethod))
throw new ArgumentOutOfRangeException("interlaceMethod", String.Format("interlaceMethod must be one of {0}", allowedInterlaceMethods.Aggregate("", (s, bd) => s + bd + ", ", s => s.Trim().Substring(0, s.Length - 2))));
#endregion
Width = width;
Height = height;
BitDepth = bitDepth;
ColorType = colorType;
CompressionMethod = compressionMethod;
FilterMethod = filterMethod;
InterlaceMethod = interlaceMethod;
}
示例10: ZipOutputStream
public ZipOutputStream(Stream baseOutputStream, int bufferSize) : base(baseOutputStream, new Deflater(-1, true), bufferSize)
{
this.entries = new ArrayList();
this.crc = new Crc32();
this.defaultCompressionLevel = -1;
this.curMethod = CompressionMethod.Deflated;
this.zipComment = new byte[0];
this.crcPatchPos = -1L;
this.sizePatchPos = -1L;
this.useZip64_ = ICSharpCode.SharpZipLib.Zip.UseZip64.Dynamic;
}
示例11: ClientHelloMessage
public ClientHelloMessage(TlsVersion version, byte[] randomBytes, byte[] sessionId, HelloExtension[] extensions, CipherSuite[] cipherSuites, CompressionMethod[] compressionMethods)
: base(HandshakeType.ClientHello, version, randomBytes, sessionId, extensions)
{
SecurityAssert.NotNull(cipherSuites);
SecurityAssert.SAssert(cipherSuites.Length >= 2 && cipherSuites.Length <= 0xFFFE);
CipherSuites = cipherSuites;
SecurityAssert.NotNull(compressionMethods);
SecurityAssert.SAssert(compressionMethods.Length >= 1 && cipherSuites.Length <= 0xFF);
CompressionMethods = compressionMethods;
}
示例12: ZipOutputStream
public ZipOutputStream(Stream baseOutputStream)
: base(baseOutputStream, new Deflater(-1, true))
{
entries = new ArrayList();
crc = new Crc32();
defaultCompressionLevel = -1;
curMethod = CompressionMethod.Deflated;
zipComment = new byte[0];
crcPatchPos = -1L;
sizePatchPos = -1L;
useZip64_ = UseZip64.Dynamic;
}
示例13: ZipOutputStream
public ZipOutputStream(Stream baseOutputStream, int bufferSize)
: base(baseOutputStream, new Deflater(-1, true), bufferSize)
{
_entries = new ArrayList();
_crc = new Crc32();
_defaultCompressionLevel = -1;
_curMethod = CompressionMethod.Deflated;
_zipComment = new byte[0];
_crcPatchPos = -1L;
_sizePatchPos = -1L;
_useZip64 = UseZip64.Dynamic;
}
示例14: MakeInMemoryZip
protected byte[] MakeInMemoryZip(ref byte[] original, CompressionMethod method,
int compressionLevel, int size, string password, bool withSeek)
{
MemoryStream ms;
if (withSeek)
{
ms = new MemoryStream();
}
else
{
ms = new MemoryStreamWithoutSeek();
}
using (ZipOutputStream outStream = new ZipOutputStream(ms))
{
outStream.Password = password;
if (method != CompressionMethod.Stored)
{
outStream.SetLevel(compressionLevel); // 0 - store only to 9 - means best compression
}
ZipEntry entry = new ZipEntry("dummyfile.tst");
entry.CompressionMethod = method;
outStream.PutNextEntry(entry);
if (size > 0)
{
System.Random rnd = new Random();
original = new byte[size];
rnd.NextBytes(original);
// Although this could be written in one chunk doing it in lumps
// throws up buffering problems including with encryption the original
// source for this change.
int index = 0;
while (size > 0)
{
int count = (size > 0x200) ? 0x200 : size;
outStream.Write(original, index, count);
size -= 0x200;
index += count;
}
}
}
return ms.ToArray();
}
示例15: GetExtensionWithoutCompression
/// <summary>
/// Returns the file extension by stripping of the extension of the
/// compressed file, if any.
/// </summary>
public static void GetExtensionWithoutCompression(Uri uri, out string path, out string extension, out CompressionMethod compressionMethod)
{
path = GetPathFromUri(uri);
extension = Path.GetExtension(path);
if (Constants.CompressionExtensions.ContainsKey(extension))
{
compressionMethod = Constants.CompressionExtensions[extension];
path = Path.GetFileNameWithoutExtension(path);
extension = Path.GetExtension(path);
}
else
{
compressionMethod = CompressionMethod.None;
}
}