public VfsFileInfo(VfsFileSystem fileSystem, FileInfo info) { _fileSystem = fileSystem; _href = VfsUtils.ToVfsUrl(fileSystem._uri, info); _fullName = info.FullName; _name = info.Name; _mime = VfsUtils.GetMediaType(info.Extension).MediaType; _exists = false; ((VfsFileInfoFactory)_fileSystem.FileInfo).UpdateCache(this); }
public VfsDirectoryInfo(VfsFileSystem fileSystem, DirectoryInfo info) { _fileSystem = fileSystem; _href = VfsUtils.ToVfsUrl(_fileSystem._uri, info); _name = info.Name; _fullName = info.FullName; _mime = VfsDirectory.Mime; _mtime = DateTime.MinValue; ((VfsDirectoryInfoFactory)_fileSystem.DirectoryInfo).UpdateCache(this); }
public override byte[] ReadAllBytes(string path) { Uri uri = VfsUtils.ToVfsUrl(_fileSystem._uri, new FileInfo(path)); using (var client = VfsUtils.NewHttpClient(uri, _fileSystem._creds)) { MemoryStream mem = new MemoryStream(); using (Stream stream = client.GetStreamAsync(uri).Result) { stream.CopyTo(mem); } return(mem.GetBuffer()); } }
public override void WriteAllBytes(string path, byte[] bytes) { FileInfo info = new FileInfo(path); Uri uri = VfsUtils.ToVfsUrl(_fileSystem._uri, info); using (var client = VfsUtils.NewHttpClient(uri, _fileSystem._creds)) { client.DefaultRequestHeaders.IfMatch.Add(EntityTagHeaderValue.Any); MemoryStream mem = new MemoryStream(bytes.Length); mem.Write(bytes, 0, bytes.Length); mem.Position = 0; StreamContent content = new StreamContent(mem); content.Headers.ContentType = VfsUtils.GetMediaType(info.Extension); using (HttpResponseMessage response = client.PutAsync(uri, content).Result.EnsureSuccessful()) { DateTime lastWriteTimeUtc = VfsUtils.GetLastWriteTimeUtc(response.Headers.ETag.Tag.Trim('\"')); ((VfsFileInfoFactory)_fileSystem.FileInfo).UpdateLastWriteTimeUtc(info.FullName, lastWriteTimeUtc); } } }