public async Task SaveAsync(MediaItem media, byte[] data) { Guard.NotNull(media, nameof(media)); // TODO: (?) if the new file extension differs from the old one then the old file never gets deleted var filePath = GetPicturePath(media); if (data != null && data.LongLength != 0) { await _fileSystem.WriteAllBytesAsync(filePath, data); } else if (_fileSystem.FileExists(filePath)) { _fileSystem.DeleteFile(filePath); } }
public Task AddImageToCacheAsync(CachedImageResult cachedImage, byte[] buffer) { if (PrepareAddImageToCache(cachedImage, buffer)) { // save file return(_fileSystem.WriteAllBytesAsync(BuildPath(cachedImage.Path), buffer)); } return(Task.FromResult(false)); }
public async Task PutAsync(CachedImageResult cachedImage, byte[] buffer) { if (PreparePut(cachedImage, buffer)) { var path = BuildPath(cachedImage.Path); // save file await _fileSystem.WriteAllBytesAsync(path, buffer); // Refresh info cachedImage.Exists = true; cachedImage.File = _fileSystem.GetFile(path); } }
public Task PutAsync(CachedImageResult cachedImage, byte[] buffer) { if (PreparePut(cachedImage, buffer)) { var path = BuildPath(cachedImage.Path); // save file var t = _fileSystem.WriteAllBytesAsync(path, buffer); t.ContinueWith(x => { // Refresh info cachedImage.Exists = true; cachedImage.File = _fileSystem.GetFile(path); }); return(t); } return(Task.FromResult(false)); }
public async Task PutAsync(CachedImageResult cachedImage, byte[] buffer) { if (PreparePut(cachedImage, buffer)) { var path = BuildPath(cachedImage.Path); // save file if (cachedImage.Extension == "svg") { await _fileSystem.WriteAllTextAsync(path, Encoding.UTF8.GetString(buffer)); } else { await _fileSystem.WriteAllBytesAsync(path, buffer); } // Refresh info cachedImage.Exists = true; cachedImage.File = _fileSystem.GetFile(path); } }