Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Dec 6, 2023
1 parent ada4e63 commit dcc4a68
Show file tree
Hide file tree
Showing 4 changed files with 246 additions and 83 deletions.
4 changes: 2 additions & 2 deletions src/EmptyFiles.Tool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
}

if (AllFiles.TryCreateFile(
path,
useEmptyStringForTextFiles: true))
path,
useEmptyStringForTextFiles: true))
{
return 0;
}
Expand Down
314 changes: 235 additions & 79 deletions src/EmptyFiles/ContentTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@ 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;
}

var slashIndex = mediaTypeSpan.LastIndexOf('/');

if (slashIndex > -1)
{
extension = mediaTypeSpan[(slashIndex + 1)..].ToString();
extension = mediaTypeSpan[(slashIndex + 1)..]
.ToString();
return true;
}

Expand All @@ -55,83 +57,237 @@ public static bool TryGetExtension(string? mediaType, [NotNullWhen(true)] out st
static Dictionary<string, string> 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"
}
};
}
7 changes: 6 additions & 1 deletion src/Tests/Size.cs
Original file line number Diff line number Diff line change
@@ -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)
{
Expand Down
4 changes: 3 additions & 1 deletion src/Tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down

0 comments on commit dcc4a68

Please sign in to comment.