From dcc4a68b4e8bfdadd3546bfe899a459b4faa7527 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Wed, 6 Dec 2023 16:24:39 +1100 Subject: [PATCH] cleanup --- src/EmptyFiles.Tool/Program.cs | 4 +- src/EmptyFiles/ContentTypes.cs | 314 ++++++++++++++++++++++++--------- src/Tests/Size.cs | 7 +- src/Tests/Tests.cs | 4 +- 4 files changed, 246 insertions(+), 83 deletions(-) diff --git a/src/EmptyFiles.Tool/Program.cs b/src/EmptyFiles.Tool/Program.cs index 494636c..0a20002 100644 --- a/src/EmptyFiles.Tool/Program.cs +++ b/src/EmptyFiles.Tool/Program.cs @@ -22,8 +22,8 @@ } if (AllFiles.TryCreateFile( - path, - useEmptyStringForTextFiles: true)) + path, + useEmptyStringForTextFiles: true)) { return 0; } diff --git a/src/EmptyFiles/ContentTypes.cs b/src/EmptyFiles/ContentTypes.cs index 939e46b..5d8022e 100644 --- a/src/EmptyFiles/ContentTypes.cs +++ b/src/EmptyFiles/ContentTypes.cs @@ -37,7 +37,8 @@ public static bool TryGetExtension(string? mediaType, [NotNullWhen(true)] out st if (plusIndex > -1) { - extension = mediaTypeSpan[(plusIndex + 1)..].ToString(); + extension = mediaTypeSpan[(plusIndex + 1)..] + .ToString(); return true; } @@ -45,7 +46,8 @@ public static bool TryGetExtension(string? mediaType, [NotNullWhen(true)] out st if (slashIndex > -1) { - extension = mediaTypeSpan[(slashIndex + 1)..].ToString(); + extension = mediaTypeSpan[(slashIndex + 1)..] + .ToString(); return true; } @@ -55,83 +57,237 @@ public static bool TryGetExtension(string? mediaType, [NotNullWhen(true)] out st static Dictionary mappings = new(StringComparer.OrdinalIgnoreCase) { //extra - {"application/graphql", "gql"}, - {"application/vnd.openxmlformats-officedocument.wordprocessingml.document", "docx"}, - {"application/vnd.openxmlformats-officedocument.wordprocessingml.template", "dotx"}, - {"application/vnd.ms-word.document.macroEnabled.12", "docm"}, - {"application/vnd.ms-word.template.macroEnabled.12", "dotm"}, - {"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "xlsx"}, - {"application/vnd.openxmlformats-officedocument.spreadsheetml.template", "xltx"}, - {"application/vnd.ms-excel.sheet.macroEnabled.12", "xlsm"}, - {"application/vnd.ms-excel.template.macroEnabled.12", "xltm"}, - {"application/vnd.ms-excel.addin.macroEnabled.12", "xlam"}, - {"application/vnd.ms-excel.sheet.binary.macroEnabled.12", "xlsb"}, - {"application/vnd.openxmlformats-officedocument.presentationml.presentation", "pptx"}, - {"application/vnd.openxmlformats-officedocument.presentationml.template", "potx"}, - {"application/vnd.openxmlformats-officedocument.presentationml.slideshow", "ppsx"}, - {"application/vnd.ms-powerpoint.addin.macroEnabled.12", "ppam"}, - {"application/vnd.ms-powerpoint.presentation.macroEnabled.12", "pptm"}, - {"application/vnd.ms-powerpoint.template.macroEnabled.12", "potm"}, - {"application/vnd.ms-powerpoint.slideshow.macroEnabled.12", "ppsm"}, + { + "application/graphql", "gql" + }, + { + "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "docx" + }, + { + "application/vnd.openxmlformats-officedocument.wordprocessingml.template", "dotx" + }, + { + "application/vnd.ms-word.document.macroEnabled.12", "docm" + }, + { + "application/vnd.ms-word.template.macroEnabled.12", "dotm" + }, + { + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "xlsx" + }, + { + "application/vnd.openxmlformats-officedocument.spreadsheetml.template", "xltx" + }, + { + "application/vnd.ms-excel.sheet.macroEnabled.12", "xlsm" + }, + { + "application/vnd.ms-excel.template.macroEnabled.12", "xltm" + }, + { + "application/vnd.ms-excel.addin.macroEnabled.12", "xlam" + }, + { + "application/vnd.ms-excel.sheet.binary.macroEnabled.12", "xlsb" + }, + { + "application/vnd.openxmlformats-officedocument.presentationml.presentation", "pptx" + }, + { + "application/vnd.openxmlformats-officedocument.presentationml.template", "potx" + }, + { + "application/vnd.openxmlformats-officedocument.presentationml.slideshow", "ppsx" + }, + { + "application/vnd.ms-powerpoint.addin.macroEnabled.12", "ppam" + }, + { + "application/vnd.ms-powerpoint.presentation.macroEnabled.12", "pptm" + }, + { + "application/vnd.ms-powerpoint.template.macroEnabled.12", "potm" + }, + { + "application/vnd.ms-powerpoint.slideshow.macroEnabled.12", "ppsm" + }, - {"application/fsharp-script", "fsx"}, - {"application/msaccess", "adp"}, - {"application/msword", "doc"}, - {"application/octet-stream", "bin"}, - {"application/onenote", "one"}, - {"application/postscript", "eps"}, - {"application/soap+xml", "xml"}, - {"application/step", "step"}, - {"application/vnd.ms-excel", "xls"}, - {"application/vnd.ms-powerpoint", "ppt"}, - {"application/vnd.ms-works", "wks"}, - {"application/vnd.visio", "vsd"}, - {"application/x-director", "dir"}, - {"application/x-msdos-program", "exe"}, - {"application/x-shockwave-flash", "swf"}, - {"application/x-x509-ca-cert", "cer"}, - {"application/x-zip-compressed", "zip"}, - {"application/xhtml+xml", "xhtml"}, - {"application/xrd+xml", "xml"}, - {"application/xml", "xml"}, - {"audio/aac", "aac"}, - {"audio/aiff", "aiff"}, - {"audio/basic", "snd"}, - {"audio/mid", "midi"}, - {"audio/mp4", "m4a"}, - {"audio/wav", "wav"}, - {"audio/x-m4a", "m4a"}, - {"audio/x-mpegurl", "m3u"}, - {"audio/x-pn-realaudio", "ra"}, - {"audio/x-smd", "smd"}, - {"image/bmp", "bmp"}, - {"image/heic", ".heic"}, - {"image/heic-sequence", "heics"}, - {"image/jpeg", "jpg"}, - {"image/gif", "gif"}, - {"image/pict", "pic"}, - {"image/png", "png"}, - {"image/x-png", "png"}, - {"image/svg+xml", "svg"}, - {"image/tiff", "tiff"}, - {"image/x-macpaint", "mac"}, - {"image/x-quicktime", "qti"}, - {"message/rfc822", "eml"}, - {"text/calendar", "ics"}, - {"text/html", "html"}, - {"text/plain", "txt"}, - {"text/scriptlet", "wsc"}, - {"text/xml", "xml"}, - {"text/csv", "csv"}, - {"video/3gpp", "3gp"}, - {"video/3gpp2", "3gp2"}, - {"video/mp4", "mp4"}, - {"video/mpeg", "mpg"}, - {"video/quicktime", "mov"}, - {"video/vnd.dlna.mpeg-tts", "m2t"}, - {"video/x-dv", "dv"}, - {"video/x-la-asf", "lsf"}, - {"video/x-ms-asf", "asf"}, - {"x-world/x-vrml", "xof"} + { + "application/fsharp-script", "fsx" + }, + { + "application/msaccess", "adp" + }, + { + "application/msword", "doc" + }, + { + "application/octet-stream", "bin" + }, + { + "application/onenote", "one" + }, + { + "application/postscript", "eps" + }, + { + "application/soap+xml", "xml" + }, + { + "application/step", "step" + }, + { + "application/vnd.ms-excel", "xls" + }, + { + "application/vnd.ms-powerpoint", "ppt" + }, + { + "application/vnd.ms-works", "wks" + }, + { + "application/vnd.visio", "vsd" + }, + { + "application/x-director", "dir" + }, + { + "application/x-msdos-program", "exe" + }, + { + "application/x-shockwave-flash", "swf" + }, + { + "application/x-x509-ca-cert", "cer" + }, + { + "application/x-zip-compressed", "zip" + }, + { + "application/xhtml+xml", "xhtml" + }, + { + "application/xrd+xml", "xml" + }, + { + "application/xml", "xml" + }, + { + "audio/aac", "aac" + }, + { + "audio/aiff", "aiff" + }, + { + "audio/basic", "snd" + }, + { + "audio/mid", "midi" + }, + { + "audio/mp4", "m4a" + }, + { + "audio/wav", "wav" + }, + { + "audio/x-m4a", "m4a" + }, + { + "audio/x-mpegurl", "m3u" + }, + { + "audio/x-pn-realaudio", "ra" + }, + { + "audio/x-smd", "smd" + }, + { + "image/bmp", "bmp" + }, + { + "image/heic", ".heic" + }, + { + "image/heic-sequence", "heics" + }, + { + "image/jpeg", "jpg" + }, + { + "image/gif", "gif" + }, + { + "image/pict", "pic" + }, + { + "image/png", "png" + }, + { + "image/x-png", "png" + }, + { + "image/svg+xml", "svg" + }, + { + "image/tiff", "tiff" + }, + { + "image/x-macpaint", "mac" + }, + { + "image/x-quicktime", "qti" + }, + { + "message/rfc822", "eml" + }, + { + "text/calendar", "ics" + }, + { + "text/html", "html" + }, + { + "text/plain", "txt" + }, + { + "text/scriptlet", "wsc" + }, + { + "text/xml", "xml" + }, + { + "text/csv", "csv" + }, + { + "video/3gpp", "3gp" + }, + { + "video/3gpp2", "3gp2" + }, + { + "video/mp4", "mp4" + }, + { + "video/mpeg", "mpg" + }, + { + "video/quicktime", "mov" + }, + { + "video/vnd.dlna.mpeg-tts", "m2t" + }, + { + "video/x-dv", "dv" + }, + { + "video/x-la-asf", "lsf" + }, + { + "video/x-ms-asf", "asf" + }, + { + "x-world/x-vrml", "xof" + } }; } \ No newline at end of file diff --git a/src/Tests/Size.cs b/src/Tests/Size.cs index dd61dae..bcbdd1c 100644 --- a/src/Tests/Size.cs +++ b/src/Tests/Size.cs @@ -1,6 +1,11 @@ static class Size { - static string[] SizeSuffixes = { "bytes", "KB", "MB"}; + static string[] SizeSuffixes = + { + "bytes", + "KB", + "MB" + }; public static string Suffix(long value) { diff --git a/src/Tests/Tests.cs b/src/Tests/Tests.cs index ea972f5..86f9eba 100644 --- a/src/Tests/Tests.cs +++ b/src/Tests/Tests.cs @@ -28,7 +28,9 @@ public void CreateFile_preamble() var preamble = Encoding.UTF8.GetPreamble(); var bytes = File.ReadAllBytes("foo.txt"); if (bytes.Length < preamble.Length || - preamble.Where((p, i) => p != bytes[i]).Any()) + preamble + .Where((p, i) => p != bytes[i]) + .Any()) { throw new ArgumentException("Not utf8-BOM"); }