Example #1
0
        private static byte[] PNGDistill(byte[] arrIn)
        {
            string sTempFile = CONFIG.GetPath("Root") + "tmpToCompress" + Guid.NewGuid();

            File.WriteAllBytes(sTempFile, arrIn);

            int iResult;

            Utilities.GetExecutableOutput(sPNGDistillPath, "\"" + sTempFile + "\"" + " REPLACE", out iResult);

            byte[] arrNew = File.ReadAllBytes(sTempFile);

            #region DeleteTempFile
            try
            {
                File.Delete(sTempFile);
                FiddlerApplication.LogLeakedFile(sTempFile);
            }
            catch
            {
                Debug.Assert(false, "Could not delete Temp Input file");
            }
            #endregion DeleteTempFile
            return(arrNew);
        }
Example #2
0
        private static byte[] BrotliCompress(byte[] arrIn, out uint iMS)
        {
            string sTempFile = CONFIG.GetPath("Root") + "tmpToCompress" + Guid.NewGuid();
            string sOutFile  = String.Concat(sTempFile, ".br");

            File.WriteAllBytes(sTempFile, arrIn);
            string sParams = String.Format("--in \"{0}\" --out \"{1}\" {2}",
                                           sTempFile,
                                           sOutFile,
                                           FiddlerApplication.Prefs.GetStringPref("extensions.compressibility.Brotli.Args", String.Empty));

            int       iExitCode = 0;
            Stopwatch oSW       = Stopwatch.StartNew();

            Utilities.GetExecutableOutput(sBrotliPath, sParams, out iExitCode);
            iMS = (uint)oSW.ElapsedMilliseconds;
            if (0 != iExitCode)
            {
                throw new Exception("Brotli conversion failed");
            }

            byte[] arrOut = File.ReadAllBytes(sOutFile);

            #region DeleteTempFiles
            try
            {
                File.Delete(sTempFile);
                FiddlerApplication.LogLeakedFile(sTempFile);
            }
            catch
            {
                Debug.Assert(false, "Could not delete Temp Input file");
            }

            try
            {
                File.Delete(sOutFile);
            }
            catch
            {
                FiddlerApplication.LogLeakedFile(sOutFile);
                Debug.Assert(false, "Could not delete Temp Output file");
            }
            #endregion DeleteTempFiles
            return(arrOut);
        }
Example #3
0
        private static byte[] ToWebP(bool bLossless, byte[] arrIn, out uint iMS)
        {
            string sTempFile = CONFIG.GetPath("Root") + "tmpToCompress" + Guid.NewGuid();
            string sOutFile  = CONFIG.GetPath("Root") + Guid.NewGuid() + ".webp";

            File.WriteAllBytes(sTempFile, arrIn);

            int iResult;

            string sArgs = bLossless ?
                           FiddlerApplication.Prefs.GetStringPref("extensions.compressibility.WebPLossless.Args", "-m 6") :
                           FiddlerApplication.Prefs.GetStringPref("extensions.compressibility.WebPLossy.Args", "-m 6");

            Stopwatch oSW = Stopwatch.StartNew();
            string    s   = Utilities.GetExecutableOutput(sCWebPPath, ((bLossless) ? "-lossless " : "") +
                                                          " " + sArgs + " \"" + sTempFile + "\" -o \"" + sOutFile + "\"", out iResult);

            iMS = (uint)oSW.ElapsedMilliseconds;

            byte[] arrNew = File.ReadAllBytes(sOutFile);

            #region DeleteTempFiles
            try
            {
                File.Delete(sTempFile);
                FiddlerApplication.LogLeakedFile(sTempFile);
            }
            catch
            {
                Debug.Assert(false, "Could not delete Temp Input file");
            }
            try
            {
                File.Delete(sOutFile);
            }
            catch
            {
                FiddlerApplication.LogLeakedFile(sOutFile);
                Debug.Assert(false, "Could not delete Temp Output file");
            }
            #endregion DeleteTempFiles
            return(arrNew);
        }