private async Task <ContentItem> CreateContentItem(IContentSource source, IReadOnlyFile file) { await Task.Yield(); //todo: do we do caching here or at build sources var type = _classifier.Classify(file); return(new ContentItem(source, type, file)); }
protected override ITexture2D PlatformLoadFromFile(uint id, IReadOnlyFile file) { _logger.LogDebug($"Loading texture {id} [{file}]"); using (var fs = file.OpenRead()) { var texture = Texture2D.FromStream(_device, fs); return(new PlatformTexture2D(id, _device, texture)); } }
public async Task <IFile> CopyFromAsync(IReadOnlyFile source, string targetName, bool overwrite, CancellationToken cancellation = default) { if (this.ContainsFile(Path.GetFileName(targetName)) && !overwrite) { throw new IOException($"{source.Name} already exists in the target directory"); } #pragma warning disable CS0618 // Type or member is obsolete return(await this.CopyFromAsync(source.UnsafeGetPath(), targetName, overwrite, cancellation)); #pragma warning restore CS0618 // Type or member is obsolete }
public IFile CopyFrom(IReadOnlyFile source, string targetName, bool overwrite) { if (this.ContainsFile(Path.GetFileName(targetName)) && !overwrite) { throw new IOException($"{Path.GetFileName(targetName)} already exists in the target directory."); } #pragma warning disable CS0618 // Type or member is obsolete return(this.CopyFrom(source.UnsafeGetPath(), overwrite)); #pragma warning restore CS0618 // Type or member is obsolete }
private async Task <IFileSystemNode> CacheFile(IReadOnlyFile sourceFile) { //todo: check if cached // create directory await _cache.GetOrCreateDirectory(sourceFile.Path.GetDirectoryPath()); // copy source to target var targetFile = await _cache.GetOrCreateFile(sourceFile.Path); await using var targetStream = await targetFile.OpenWrite(); await using var sourceStream = await sourceFile.OpenRead(); await sourceStream.CopyToAsync(targetStream); return(targetFile); }
public string Classify(IReadOnlyFile file) { var path = file.Path.ToString(); var extension = System.IO.Path.GetExtension(path); var filename = System.IO.Path.GetFileNameWithoutExtension(path); // builtIn overrides var builtIn = GetBuiltIn(filename, extension); if (!string.IsNullOrEmpty(builtIn)) { return(builtIn); } // mime-db lookup if (MimeType.TryGet(extension, out var mimeType)) { return(mimeType.Type); } return("__unknown"); }
public ContentItem(IContentSource source, string type, IReadOnlyFile file) { Type = type; File = file; _source = source; }
public Task <IFile> CopyFromAsync(IReadOnlyFile source, bool overwrite, CancellationToken cancellation = default) => this.Base.CopyFromAsync(source, overwrite, cancellation);
public IFile CopyFrom(IReadOnlyFile source, bool overwrite) => this.Base.CopyFrom(source);
public IFile CopyFrom(IReadOnlyFile source) => this.Base.CopyFrom(source);
public IFile CopyFrom(IReadOnlyFile source, string targetName, bool overwrite) => this.Base.CopyFrom(source, targetName, overwrite);
public IFile CopyFrom(IReadOnlyFile source, string targetName) => this.Base.CopyFrom(source, targetName);
/// <summary> /// Opens a text file, reads all the text in the file into a string with the specified encoding, /// and then closes the opened stream. /// </summary> /// <param name="this">The <see cref="IFile"/> to read.</param> /// <param name="encoding">The encoding applied to the contents of the file.</param> /// <returns>A string containing all text in the file.</returns> public static string ReadAllText(this IReadOnlyFile @this, Encoding encoding) { using var fileStream = @this.OpenReadStream(); using var stringReader = new StreamReader(fileStream, encoding); return(stringReader.ReadToEnd()); }
/// <summary> /// Opens a text file, reads all the text in the file into a string, and then closes the opened stream. /// The default encoding is UTF8. /// </summary> /// <param name="this">The <see cref="IFile"/> to read.</param> /// <returns>A string containing all text in the file.</returns> public static string ReadAllText(this IReadOnlyFile @this) => FileExtensions.ReadAllText(@this, Encoding.UTF8);
public IFile CopyFrom(IReadOnlyFile source) => this.CopyFrom(source, false);
public IFile CopyFrom(IReadOnlyFile source, bool overwrite) => this.CopyFrom(source, source.Name, overwrite);
public Task <IFile> CopyFromAsync(IReadOnlyFile source, string targetName, CancellationToken cancellation = default) => this.Base.CopyFromAsync(source, targetName, cancellation);
public Task <IFile> CopyFromAsync(IReadOnlyFile source, CancellationToken cancellation = default) => this.CopyFromAsync(source, false, cancellation);