private bool BeAValidArchiveType(IFormFile file) { var isValid = false; foreach (var extension in ArchiveTypeHelpers.GetValidExtensions()) { if (file.FileName.ToLower().EndsWith(extension)) { isValid = true; } } return(isValid); }
private void Extract(System.IO.Stream stream, string filename, Project project = null, Directory directory = null) { using (var archiveInputStream = ArchiveInputStream.Create(stream, ArchiveTypeHelpers.GetType(filename))) { while (archiveInputStream.GetNextEntry() is ArchiveEntry archiveEntry) { var file = this.EnsureCreated(project, directory, archiveEntry.Name, archiveEntry.IsFile); if (file != null && archiveEntry.IsFile) { var buffer = new byte[4096]; using (var contentStream = new System.IO.MemoryStream()) { StreamUtils.Copy(archiveInputStream.Stream, contentStream, buffer); file.Content = Encoding.ASCII.GetString(contentStream.ToArray()); } } } } }
public ImportValidator() { RuleFor(x => x.Archive) .NotNull().Must(BeAValidArchiveType) .WithMessage($"File extension must be one of {string.Join(", ", ArchiveTypeHelpers.GetValidExtensions())}"); }