Home

Awesome

<img src="/src/icon.png" height="30px"> EmptyFiles

Discussions Build status NuGet Status NuGet Status

A collection of minimal binary files.

See Milestones for release notes.

NuGet package

Files

All files: https://github.com/VerifyTests/EmptyFiles/tree/main/files

<!-- include: extensions. path: /src/extensions.include.md -->

Archive

Document

Image

Sheet

Slide

Consuming files as a web resource

Files can be consumed as a web resource using the following url:

https://github.com/VerifyTests/EmptyFiles/raw/main/index/empty.{extension}

So for example to consume a jpg use

https://github.com/VerifyTests/EmptyFiles/raw/main/index/empty.jpg

A 404 will result for non-existent files.

Tool Usage

Installation

Ensure dotnet CLI is installed.

Install EmptyFiles.Tool

dotnet tool install -g EmptyFiles.Tool

Extension only Usage

emptyfile bmp

Creates {CurrentDirectory}/empty.bmp

File Usage

emptyfile myfile.bmp

Creates {CurrentDirectory}/myfile.bmp

Path Usage

emptyfile path/myfile.bmp

Creates path/myfile.bmp

Library Usage

CreateFile

Creates a new empty file

<!-- snippet: CreateFile -->

<a id='snippet-CreateFile'></a>

AllFiles.CreateFile(pathOfFileToCreate);

<sup><a href='/src/Tests/Tests.cs#L136-L140' title='Snippet source file'>snippet source</a> | <a href='#snippet-CreateFile' title='Start of snippet'>anchor</a></sup>

<!-- endSnippet -->

Throws an exception if the extension is not known. There is also a TryCreateFile that will return false if the extension is not known.

Use the optional useEmptyStringForTextFiles to create a empty text file if the extension is text. The file will be UTF8 no BOM as per https://www.unicode.org/versions/Unicode5.0.0/ch02.pdf "Use of a BOM is neither required nor recommended for UTF-8".

GetPathFor

Gets the path to an empty file for a given extension

<!-- snippet: GetPathFor -->

<a id='snippet-GetPathFor'></a>

var path = AllFiles.GetPathFor(".jpg");

<sup><a href='/src/Tests/Tests.cs#L116-L120' title='Snippet source file'>snippet source</a> | <a href='#snippet-GetPathFor' title='Start of snippet'>anchor</a></sup>

<!-- endSnippet -->

Throws an exception if the extension is not known. There is also a TryGetPathFor that will return false if the extension is not known.

IsEmptyFile

Returns true if the target file is an empty file.

<!-- snippet: IsEmptyFile -->

<a id='snippet-IsEmptyFile'></a>

var path = AllFiles.GetPathFor(".jpg");
True(AllFiles.IsEmptyFile(path));
var temp = Path.GetTempFileName();
False(AllFiles.IsEmptyFile(temp));

<sup><a href='/src/Tests/Tests.cs#L165-L172' title='Snippet source file'>snippet source</a> | <a href='#snippet-IsEmptyFile' title='Start of snippet'>anchor</a></sup>

<!-- endSnippet -->

AllPaths

Enumerates all empty files

<!-- snippet: AllPaths -->

<a id='snippet-AllPaths'></a>

foreach (var path in AllFiles.AllPaths)
{
    Trace.WriteLine(path);
}

<sup><a href='/src/Tests/Tests.cs#L182-L189' title='Snippet source file'>snippet source</a> | <a href='#snippet-AllPaths' title='Start of snippet'>anchor</a></sup>

<!-- endSnippet -->

UseFile

Use or replace a file

<!-- snippet: UseFile -->

<a id='snippet-UseFile'></a>

AllFiles.UseFile(Category.Document, pathToFile);
IsTrue(AllFiles.DocumentPaths.Contains(pathToFile));

<sup><a href='/src/Tests/Tests.cs#L202-L207' title='Snippet source file'>snippet source</a> | <a href='#snippet-UseFile' title='Start of snippet'>anchor</a></sup>

<!-- endSnippet -->

Extensions helper

IsText

https://github.com/sindresorhus/text-extensions/blob/master/text-extensions.json

<!-- snippet: IsText -->

<a id='snippet-IsText'></a>

True(FileExtensions.IsTextFile("file.txt"));
False(FileExtensions.IsTextFile("file.bin"));
True(FileExtensions.IsTextExtension(".txt"));
False(FileExtensions.IsTextExtension(".bin"));
True(FileExtensions.IsTextExtension("txt"));
False(FileExtensions.IsTextExtension("bin"));

<sup><a href='/src/Tests/ExtensionsTests.cs#L6-L15' title='Snippet source file'>snippet source</a> | <a href='#snippet-IsText' title='Start of snippet'>anchor</a></sup>

<!-- endSnippet -->

AddTextExtension

<!-- snippet: AddTextExtension -->

<a id='snippet-AddTextExtension'></a>

FileExtensions.AddTextExtension(".ext1");
True(FileExtensions.IsTextExtension(".ext1"));
True(FileExtensions.IsTextFile("file.ext1"));

<sup><a href='/src/Tests/ExtensionsTests.cs#L36-L42' title='Snippet source file'>snippet source</a> | <a href='#snippet-AddTextExtension' title='Start of snippet'>anchor</a></sup>

<!-- endSnippet -->

RemoveTextExtension

<!-- snippet: RemoveTextExtension -->

<a id='snippet-RemoveTextExtension'></a>

FileExtensions.AddTextExtension(".ext1");
True(FileExtensions.IsTextExtension(".ext1"));
FileExtensions.RemoveTextExtension(".ext1");
False(FileExtensions.IsTextExtension(".ext1"));

<sup><a href='/src/Tests/ExtensionsTests.cs#L52-L59' title='Snippet source file'>snippet source</a> | <a href='#snippet-RemoveTextExtension' title='Start of snippet'>anchor</a></sup>

<!-- endSnippet -->

Icon

Hollow designed by Michael Senkow from The Noun Project.