static void Main(string[] args) { CompressionSettings settings; try { settings = new CompressionSettings(args); } catch (Exception e) { Console.WriteLine(e.Message); Console.ReadKey(); return; } Console.WriteLine("Try to {0} file '{1}'", settings.CompressionMode.ToString().ToLower(), settings.InputFile); var stopwatch = Stopwatch.StartNew(); StreamManager streamManager = new StreamManager(settings); streamManager.Run(); stopwatch.Stop(); Console.WriteLine("{0}ion completed", settings.CompressionMode); Console.WriteLine("Time elapsed: {0:0.000}s", stopwatch.Elapsed.TotalSeconds); Console.ReadKey(); }
public static Status CompressBuffer(byte[] rawBuf, out byte[] compBuf) { if (rawBuf.Length > 256) { //var compressedBufferSizeNeeded = GetCompressedBufferSizeNeeded(rawBuf.Length); //var compressedBuffer = new byte[compressedBufferSizeNeeded]; IEnumerable <byte> compressedBuffer = new List <byte>(); var compressedSize = Oodle.Compress(rawBuf, ref compressedBuffer, false, CompressionSettings.Get().CompressionLevel); var outArray = new byte[compressedSize + 8]; Array.Copy(BitConverter.GetBytes(KARK), 0, outArray, 0, 4); Array.Copy(BitConverter.GetBytes(rawBuf.Length), 0, outArray, 4, 4); Array.Copy(compressedBuffer.ToArray(), 0, outArray, 8, compressedSize); if (rawBuf.Length > outArray.Length) { compBuf = outArray; return(Status.Compressed); } } compBuf = rawBuf; return(Status.Uncompressed); }
public static long Decompress(byte[] inputBuffer, byte[] outputBuffer) { var result = 0; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { result = CompressionSettings.Get().UseOodle ? OodleLib.OodleLZ_Decompress(inputBuffer, outputBuffer) : KrakenNative.Decompress(inputBuffer, outputBuffer); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { result = KrakenNative.Decompress(inputBuffer, outputBuffer); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { result = OozNative.Kraken_Decompress(inputBuffer, outputBuffer); } else { throw new NotImplementedException(); } return(result); }
public const uint KARK = 1263681867; // 0x4b, 0x41, 0x52, 0x4b public static bool Load() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { // try get oodle dll from game if (TryCopyOodleLib()) { var result = OodleLib.Load(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "oo2ext_7_win64.dll")); if (result) { CompressionSettings.Get().CompressionLevel = CompressionLevel.Optimal2; CompressionSettings.Get().UseOodle = true; return(true); } } return(true); } if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { return(true); } if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { return(true); } throw new NotImplementedException(); }
/// <summary> /// Create a TaskHubClientSettings object with default settings /// </summary> public TaskHubClientSettings() { MessageCompressionSettings = new CompressionSettings { Style = CompressionStyle.Never, ThresholdInBytes = 0 }; }
internal Compressor(CompressionSettings settings, Stream stream) { ChunkSize = settings.ChunkSize; m_threads = new ThreadManager(settings.ThreadsCount); m_queue = new BoundedQueue(settings.BufferCapacity); m_outputStream = new OutputStream(stream); m_threads.OnExceptionOccured += threads_OnExceptionOccured; }
internal override void CopyFrom(CompressionSettings baseSettings) { DeflateSettings deflateSettings = baseSettings as DeflateSettings; if (deflateSettings == null) { return; } this.HeaderType = deflateSettings.HeaderType; this.CompressionLevel = deflateSettings.CompressionLevel; }
/// <summary> /// Create a TaskHubWorkerSettings object with default settings /// </summary> public TaskHubWorkerSettings() { TaskOrchestrationDispatcherSettings = new TaskOrchestrationDispatcherSettings(); TaskActivityDispatcherSettings = new TaskActivityDispatcherSettings(); TrackingDispatcherSettings = new TrackingDispatcherSettings(); MessageCompressionSettings = new CompressionSettings { Style = CompressionStyle.Never, ThresholdInBytes = 0 }; }
internal override void CopyFrom(CompressionSettings baseSettings) { LzmaSettings lzmaSettings = baseSettings as LzmaSettings; if (lzmaSettings == null) { return; } this.UseZipHeader = lzmaSettings.UseZipHeader; this.DictionarySize = lzmaSettings.DictionarySize; this.PositionStateBits = lzmaSettings.PositionStateBits; this.LiteralContextBits = lzmaSettings.LiteralContextBits; this.LiteralPositionBits = lzmaSettings.LiteralPositionBits; this.FastBytes = lzmaSettings.FastBytes; this.MatchFinderType = lzmaSettings.MatchFinderType; }
public static void CreateFromDirectory( string sourceDirectoryName, string destinationArchiveFileName, CompressionSettings compressionSettings, bool includeBaseDirectory, Encoding entryNameEncoding) { char[] chArray = new char[2] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }; sourceDirectoryName = Path.GetFullPath(sourceDirectoryName); destinationArchiveFileName = Path.GetFullPath(destinationArchiveFileName); using (ZipArchive destination = ZipFile.Open(destinationArchiveFileName, ZipArchiveMode.Create, entryNameEncoding)) { bool flag = true; DirectoryInfo directoryInfo1 = new DirectoryInfo(sourceDirectoryName); string fullName = directoryInfo1.FullName; if (includeBaseDirectory && directoryInfo1.Parent != null) { fullName = directoryInfo1.Parent.FullName; } foreach (FileSystemInfo fileSystemInfo in ZipFile.GetAllFilesRecursively(directoryInfo1)) { flag = false; int length = fileSystemInfo.FullName.Length - fullName.Length; string entryName = fileSystemInfo.FullName.Substring(fullName.Length, length).TrimStart(chArray); DirectoryInfo directoryInfo2 = fileSystemInfo as DirectoryInfo; if (directoryInfo2 != null) { if (ZipFile.IsDirectoryEmpty(directoryInfo2)) { destination.CreateEntry(entryName + (object)Path.DirectorySeparatorChar); } } else { ZipFile.CreateEntryFromFile(destination, fileSystemInfo.FullName, entryName, compressionSettings); } } if (!includeBaseDirectory || !flag) { return; } destination.CreateEntry(directoryInfo1.Name + (object)Path.DirectorySeparatorChar); } }
public static ZipArchiveEntry CreateEntryFromFile( ZipArchive destination, string sourceFileName, string entryName, CompressionSettings compressionSettings) { if (destination == null) { throw new ArgumentNullException(nameof(destination)); } if (sourceFileName == null) { throw new ArgumentNullException(nameof(sourceFileName)); } if (entryName == null) { throw new ArgumentNullException(nameof(entryName)); } ZipArchiveEntry zipArchiveEntry; using (Stream stream1 = (Stream)File.Open(sourceFileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { zipArchiveEntry = compressionSettings == null?destination.CreateEntry(entryName) : destination.CreateEntry(entryName, compressionSettings); zipArchiveEntry.ExternalAttributes = (int)File.GetAttributes(sourceFileName); DateTime dateTime = File.GetLastWriteTime(sourceFileName); if (dateTime.Year < 1980 || dateTime.Year > 2107) { dateTime = new DateTime(1980, 1, 1, 0, 0, 0); } zipArchiveEntry.LastWriteTime = (DateTimeOffset)dateTime; Stream stream2 = zipArchiveEntry.Open(); byte[] buffer = new byte[4096]; int count; while ((count = stream1.Read(buffer, 0, buffer.Length)) != 0) { stream2.Write(buffer, 0, count); } if (destination.Mode == ZipArchiveMode.Create) { stream2.Dispose(); zipArchiveEntry.Dispose(); } } return(zipArchiveEntry); }
public async Task AsyncImpl_CompressDataAndThenDecompress_ResultIdenticalData(Type type) { byte[] data = new byte[1024 * 1024]; for (int i = data.Length - 1; i >= 0; i--) { data[i] = (byte)(new Random().NextDouble() > 0.5d ? 5 : 75); } var compressionSettings = new CompressionSettings { bufferSize = 1024 }; byte[] compressed = await GetImpl(type).Compress(data, compressionSettings); byte[] decompressed = await GetImpl(type).Decompress(compressed, compressionSettings); Assert.Equal(data, decompressed); }
/// <summary> /// Create a TaskHubWorkerSettings object with default settings /// </summary> public ServiceBusOrchestrationServiceSettings() { MaxTaskOrchestrationDeliveryCount = ServiceBusConstants.MaxDeliveryCount; MaxTaskActivityDeliveryCount = ServiceBusConstants.MaxDeliveryCount; MaxTrackingDeliveryCount = ServiceBusConstants.MaxDeliveryCount; TaskOrchestrationDispatcherSettings = new TaskOrchestrationDispatcherSettings(); TaskActivityDispatcherSettings = new TaskActivityDispatcherSettings(); TrackingDispatcherSettings = new TrackingDispatcherSettings(); JumpStartSettings = new JumpStartSettings(); SessionSettings = new ServiceBusSessionSettings(); MessageSettings = new ServiceBusMessageSettings(); MessageCompressionSettings = new CompressionSettings { Style = CompressionStyle.Never, ThresholdInBytes = 0 }; }
public const uint KARK = 1263681867; // 0x4b, 0x41, 0x52, 0x4b public static bool Load() { // try get oodle dll from game if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { var result = false; if (TryCopyOodleLib()) { result = OodleLib.Load(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "oo2ext_7_win64.dll")); if (result) { CompressionSettings.Get().CompressionLevel = CompressionLevel.Optimal2; CompressionSettings.Get().UseOodle = true; return(true); } } // try load Kraken result = KrakenLib.Load(); if (result) { return(true); } Log.Error("Could not automatically find oo2ext_7_win64.dll. " + "Please manually copy and paste the DLL found in <gamedir>\\Cyberpunk 2077\\bin\\x64\\oo2ext_7_win64.dll into this folder: " + $"{AppDomain.CurrentDomain.BaseDirectory}."); return(false); } if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { return(KrakenLib.Load()); } if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { } throw new NotImplementedException(); }
internal Decompressor(CompressionSettings settings, Stream stream) : base(settings, stream) { }
/// <summary> /// Compression settings. /// </summary> /// <param name="settings">Compression settings</param> public void Compression(CompressionSettings settings) { _pdfReport.DataBuilder.DefaultCompression(settings); }
public static int Compress(byte[] inputBuffer, ref IEnumerable <byte> outputBuffer, bool useRedHeader, CompressionLevel level = CompressionLevel.Normal, Compressor compressor = Compressor.Kraken) { if (inputBuffer == null) { throw new ArgumentNullException(nameof(inputBuffer)); } var inputCount = inputBuffer.Length; if (inputCount <= 0 || inputCount > inputBuffer.Length) { throw new ArgumentOutOfRangeException(nameof(inputCount)); } if (outputBuffer == null) { throw new ArgumentNullException(nameof(outputBuffer)); } var result = 0; var compressedBufferSizeNeeded = Oodle.GetCompressedBufferSizeNeeded(inputCount); var compressedBuffer = new byte[compressedBufferSizeNeeded]; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { result = CompressionSettings.Get().UseOodle ? OodleLib.OodleLZ_Compress(inputBuffer, compressedBuffer, compressor, level) : KrakenNative.Compress(inputBuffer, compressedBuffer, (int)level); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { result = KrakenNative.Compress(inputBuffer, compressedBuffer, (int)level); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { result = OozNative.Kraken_Compress(inputBuffer, compressedBuffer, (int)level); } else { throw new NotImplementedException(); } if (result == 0 || inputCount <= (result + 8)) { outputBuffer = inputBuffer; return(outputBuffer.Count()); } if (useRedHeader) { // write KARK header var writelist = new List <byte>() { 0x4B, 0x41, 0x52, 0x4B //KARK, TODO: make this dependent on the compression algo }; // write size writelist.AddRange(BitConverter.GetBytes(inputCount)); // write compressed data writelist.AddRange(compressedBuffer.Take(result)); outputBuffer = writelist; } else { outputBuffer = compressedBuffer.Take(result); } return(outputBuffer.Count()); }
/// <summary> /// Constructs a instance of Uglify JS minifier /// </summary> /// <param name="createJsEngineInstance">Delegate that creates an instance of JS engine</param> /// <param name="uglifyConfig">Configuration settings of Uglify Minifier</param> public UglifyJsMinifier(Func <IJsEngine> createJsEngineInstance, UglifySettings uglifyConfig) { JsMinifierSettings jsMinifierConfig = uglifyConfig.Js; ParsingSettings parsingConfig = jsMinifierConfig.Parsing; CompressionSettings compressionConfig = jsMinifierConfig.Compression; ManglingSettings manglingConfig = jsMinifierConfig.Mangling; CodeGenerationSettings codeGenerationConfig = jsMinifierConfig.CodeGeneration; ParsingOptions = new ParsingOptions { BareReturns = parsingConfig.BareReturns, Strict = parsingConfig.Strict }; CompressionOptions = new CompressionOptions { Angular = compressionConfig.Angular, Booleans = compressionConfig.Booleans, Cascade = compressionConfig.Cascade, CollapseVars = compressionConfig.CollapseVars, Comparisons = compressionConfig.Comparisons, Compress = compressionConfig.Compress, Conditionals = compressionConfig.Conditionals, DeadCode = compressionConfig.DeadCode, DropConsole = compressionConfig.DropConsole, DropDebugger = compressionConfig.DropDebugger, Evaluate = compressionConfig.Evaluate, GlobalDefinitions = compressionConfig.GlobalDefinitions, HoistFunctions = compressionConfig.HoistFunctions, HoistVars = compressionConfig.HoistVars, IfReturn = compressionConfig.IfReturn, JoinVars = compressionConfig.JoinVars, KeepFunctionArgs = compressionConfig.KeepFunctionArgs, KeepInfinity = compressionConfig.KeepInfinity, Loops = compressionConfig.Loops, NegateIife = compressionConfig.NegateIife, Passes = compressionConfig.Passes, PropertiesDotNotation = compressionConfig.PropertiesDotNotation, PureGetters = compressionConfig.PureGetters, PureFunctions = compressionConfig.PureFunctions, ReduceVars = compressionConfig.ReduceVars, Sequences = compressionConfig.Sequences, TopLevel = compressionConfig.TopLevel, TopRetain = compressionConfig.TopRetain, Unsafe = compressionConfig.Unsafe, UnsafeMath = compressionConfig.UnsafeMath, UnsafeProto = compressionConfig.UnsafeProto, UnsafeRegExp = compressionConfig.UnsafeRegExp, Unused = compressionConfig.Unused }; ManglingOptions = new ManglingOptions { Eval = manglingConfig.Eval, Except = manglingConfig.Except, Mangle = manglingConfig.Mangle, TopLevel = manglingConfig.TopLevel, }; CodeGenerationOptions = new CodeGenerationOptions { AsciiOnly = codeGenerationConfig.AsciiOnly, Beautify = codeGenerationConfig.Beautify, Bracketize = codeGenerationConfig.Bracketize, Comments = codeGenerationConfig.Comments, IndentLevel = codeGenerationConfig.IndentLevel, IndentStart = codeGenerationConfig.IndentStart, InlineScript = codeGenerationConfig.InlineScript, KeepQuotedProperties = codeGenerationConfig.KeepQuotedProperties, MaxLineLength = codeGenerationConfig.MaxLineLength, PreserveLine = codeGenerationConfig.PreserveLine, QuoteKeys = codeGenerationConfig.QuoteKeys, QuoteStyle = codeGenerationConfig.QuoteStyle, Semicolons = codeGenerationConfig.Semicolons, SpaceColon = codeGenerationConfig.SpaceColon, UnescapeRegexps = codeGenerationConfig.UnescapeRegexps, Width = codeGenerationConfig.Width, WrapIife = codeGenerationConfig.WrapIife }; KeepFunctionNames = jsMinifierConfig.KeepFunctionNames; ScrewIe8 = jsMinifierConfig.ScrewIe8; Severity = jsMinifierConfig.Severity; if (createJsEngineInstance == null) { string jsEngineName = uglifyConfig.JsEngine.Name; if (string.IsNullOrWhiteSpace(jsEngineName)) { throw new ConfigurationErrorsException( string.Format(CoreStrings.Configuration_JsEngineNotSpecified, "uglify", @" * JavaScriptEngineSwitcher.Msie * JavaScriptEngineSwitcher.V8 * JavaScriptEngineSwitcher.ChakraCore", "MsieJsEngine") ); } createJsEngineInstance = () => JsEngineSwitcher.Instance.CreateEngine(jsEngineName); } _createJsEngineInstance = createJsEngineInstance; }
public StreamManager(CompressionSettings settings) { m_settings = settings; }
public void Initialize(CompressionSettings settings) { }
public static Task <BrokeredMessage> GetBrokeredMessageFromObjectAsync(object serializableObject, CompressionSettings compressionSettings) { return(GetBrokeredMessageFromObjectAsync(serializableObject, compressionSettings, new ServiceBusMessageSettings(), null, null, null, DateTimeUtils.MinDateTime)); }
/// <summary> /// Compression settings. /// If you are setting SetDocumentPreferences method or DocumentPreferences property value directly, ignore this method. /// </summary> /// <param name="compression">Compression settings</param> public void DefaultCompression(CompressionSettings compression) { _pdfRptCompression = compression; }
public static Compressor Create(CompressionSettings settings, Stream stream) { return(settings.CompressionMode == CompressionMode.Decompress ? new Decompressor(settings, stream) : new Compressor(settings, stream)); }
public static async Task <BrokeredMessage> GetBrokeredMessageFromObjectAsync( object serializableObject, CompressionSettings compressionSettings, ServiceBusMessageSettings messageSettings, OrchestrationInstance instance, string messageType, IOrchestrationServiceBlobStore orchestrationServiceBlobStore, DateTime messageFireTime) { if (serializableObject == null) { throw new ArgumentNullException(nameof(serializableObject)); } if (compressionSettings.Style == CompressionStyle.Legacy) { return(new BrokeredMessage(serializableObject) { SessionId = instance?.InstanceId }); } if (messageSettings == null) { messageSettings = new ServiceBusMessageSettings(); } bool disposeStream = true; var rawStream = new MemoryStream(); Utils.WriteObjectToStream(rawStream, serializableObject); try { BrokeredMessage brokeredMessage = null; if (compressionSettings.Style == CompressionStyle.Always || (compressionSettings.Style == CompressionStyle.Threshold && rawStream.Length > compressionSettings.ThresholdInBytes)) { Stream compressedStream = Utils.GetCompressedStream(rawStream); var rawLen = rawStream.Length; TraceHelper.TraceInstance( TraceEventType.Information, "GetBrokeredMessageFromObject-CompressionStats", instance, () => "Compression stats for " + (messageType ?? string.Empty) + " : " + brokeredMessage?.MessageId + ", uncompressed " + rawLen + " -> compressed " + compressedStream.Length); if (compressedStream.Length < messageSettings.MessageOverflowThresholdInBytes) { brokeredMessage = GenerateBrokeredMessageWithCompressionTypeProperty(compressedStream, FrameworkConstants.CompressionTypeGzipPropertyValue); } else { brokeredMessage = await GenerateBrokeredMessageWithBlobKeyPropertyAsync(compressedStream, orchestrationServiceBlobStore, instance, messageSettings, messageFireTime, FrameworkConstants.CompressionTypeGzipPropertyValue); } } else { if (rawStream.Length < messageSettings.MessageOverflowThresholdInBytes) { brokeredMessage = GenerateBrokeredMessageWithCompressionTypeProperty(rawStream, FrameworkConstants.CompressionTypeNonePropertyValue); disposeStream = false; } else { brokeredMessage = await GenerateBrokeredMessageWithBlobKeyPropertyAsync(rawStream, orchestrationServiceBlobStore, instance, messageSettings, messageFireTime, FrameworkConstants.CompressionTypeNonePropertyValue); } } brokeredMessage.SessionId = instance?.InstanceId; // TODO : Test more if this helps, initial tests shows not change in performance // brokeredMessage.ViaPartitionKey = instance?.InstanceId; return(brokeredMessage); } finally { if (disposeStream) { rawStream.Dispose(); } } }
internal AfdRouteCacheConfiguration(AfdQueryStringCachingBehavior?queryStringCachingBehavior, string queryParameters, CompressionSettings compressionSettings) { QueryStringCachingBehavior = queryStringCachingBehavior; QueryParameters = queryParameters; CompressionSettings = compressionSettings; }