HTTP file system
This file system provides a read-only implementation for a file system based on the HTTP protocol. It does not browse the server directory listing itself - instead, each directory must contain a .dirls file describing its content, in the format:
D/F Length Created Modified Hash Algorithm Hash NameThis file is generated by the TagBites.IO.Http.HttpFileSystem.CreateDirectoryInfo method, which walks a directory (recursively, by default) and writes a .dirls file into it and every subdirectory:
// Publish an existing directory (e.g. before uploading it to a web server)HttpFileSystem.CreateDirectoryInfo(FileSystem.Local.GetDirectory("wwwroot/files"));Alternatively, CreateRecursiveDirectoryInfo writes a single .dirrls file at the root containing entries for the whole directory tree. It is picked up automatically for a recursive listing of the root directory, avoiding one HTTP request per subdirectory:
HttpFileSystem.CreateRecursiveDirectoryInfo(FileSystem.Local.GetDirectory("wwwroot/files"), ignoredPaths: new[] { "temp" });FileSystem fileSystem = TagBites.IO.Http.HttpFileSystem.Create("address");// ... using like standard file systemAdditional options - custom .dirls file name, text encoding and request timeout - can be passed with HttpFileSystemOptions:
FileSystem fileSystem = TagBites.IO.Http.HttpFileSystem.Create("address", new HttpFileSystemOptions{ DirectoryInfoFileName = ".dirls", Timeout = 10000, PreventCache = true});Publishing through another file system
Section titled “Publishing through another file system”Because the HTTP file system itself is read-only, content is typically published through another writable file system (e.g. FTP) that uploads to the same address the HTTP file system later reads from. CreateBuilder wraps such a file system so every write automatically (re)creates the .dirls file for the affected directory, keeping it in sync without calling CreateDirectoryInfo by hand:
var ftpFileSystem = TagBites.IO.Ftp.FtpFileSystem.Create(address, username, password);FileSystem publishFileSystem = TagBites.IO.Http.HttpFileSystem.CreateBuilder(ftpFileSystem);
// writes go to FTP and keep .dirls files up to dateawait publishFileSystem.GetFile("file.txt").WriteAllTextAsync("content");
// reads later happen through plain HTTPFileSystem fileSystem = TagBites.IO.Http.HttpFileSystem.Create(address);Full implementation on github: TagBites.IO.Http.