Aries.CodeDOMCompiler.SetBytes C# (CSharp) Method

SetBytes() public static method

Return the size of a file (used when showing a file size in the debug panel)
public static SetBytes ( byte bytes, bool fromFile ) : string
bytes byte File location if retrieving from a file on the HDD, or a byte array if not
fromFile bool Whether or not the parameter 'bytes' is a file on the HDD
return string
        public static string SetBytes(byte[] bytes, bool fromFile)
        {
            try
            {
                if (fromFile) { bytes = System.IO.File.ReadAllBytes(Encoding.Default.GetString(bytes)); }

                if (bytes.Length >= 1073741824)
                {
                    return String.Format(Convert.ToString(bytes.Length / 1024 / 1024 / 1024), "#0.00") + " GB";
                }
                else if (bytes.Length >= 1048576)
                {
                    return String.Format(Convert.ToString(bytes.Length / 1024 / 1024), "#0.00") + " MB";
                }
                else if (bytes.Length >= 1024)
                {
                    return String.Format(Convert.ToString(bytes.Length / 1024), "#0.00") + " KB";
                }
                else if (bytes.Length < 1024)
                {
                    return bytes.Length + " Bytes";
                }
                return "0 Bytes";
            }

            catch (Exception)
            {
                return "Error retrieving file size";
            }
        }