| | 1 | | namespace Songhay.Extensions; |
| | 2 | |
|
| | 3 | | /// <summary> |
| | 4 | | /// Extension of <see cref="FileInfo"/> |
| | 5 | | /// </summary> |
| | 6 | | public static class FileInfoExtensions |
| | 7 | | { |
| | 8 | | /// <summary> |
| | 9 | | /// Read zip archive entries. |
| | 10 | | /// </summary> |
| | 11 | | /// <param name="archiveInfo">The <see cref="FileInfo"/>.</param> |
| | 12 | | /// <param name="fileAction">The file action.</param> |
| | 13 | | /// <remarks> |
| | 14 | | /// Use <c>entriesProjector</c> for any filtering or sorting. |
| | 15 | | /// </remarks> |
| | 16 | | public static void ReadZipArchiveEntries(this FileInfo archiveInfo, Action<string> fileAction) => |
| 1 | 17 | | ProgramFileUtility.ReadZipArchiveEntries(archiveInfo, fileAction); |
| | 18 | |
|
| | 19 | | /// <summary> |
| | 20 | | /// Read zip archive entries. |
| | 21 | | /// </summary> |
| | 22 | | /// <param name="archiveInfo">The <see cref="FileInfo"/>.</param> |
| | 23 | | /// <param name="fileAction">The file action.</param> |
| | 24 | | /// <param name="entriesProjector">The entries projector.</param> |
| | 25 | | /// <remarks> |
| | 26 | | /// Use <c>entriesProjector</c> for any filtering or sorting. |
| | 27 | | /// </remarks> |
| | 28 | | public static void ReadZipArchiveEntries(this FileInfo archiveInfo, Action<string> fileAction, |
| | 29 | | Func<ReadOnlyCollection<ZipArchiveEntry>, IEnumerable<ZipArchiveEntry>> entriesProjector) => |
| 1 | 30 | | ProgramFileUtility.ReadZipArchiveEntries(archiveInfo, fileAction, entriesProjector); |
| | 31 | |
|
| | 32 | | /// <summary> |
| | 33 | | /// Read zip archive entries as strings, line by line. |
| | 34 | | /// </summary> |
| | 35 | | /// <param name="archiveInfo">The file and/or directory info.</param> |
| | 36 | | /// <param name="lineAction">The line action.</param> |
| | 37 | | /// <remarks> |
| | 38 | | /// This member is designed for compressed text documents that are too large to load into memory. |
| | 39 | | /// The <c>fileAction</c> includes the line number and the current line. |
| | 40 | | /// </remarks> |
| | 41 | | public static void ReadZipArchiveEntriesByLine(this FileInfo archiveInfo, Action<int, string> lineAction) => |
| 0 | 42 | | ProgramFileUtility.ReadZipArchiveEntriesByLine(archiveInfo, lineAction); |
| | 43 | |
|
| | 44 | | /// <summary> |
| | 45 | | /// Read zip archive entries as strings, line by line. |
| | 46 | | /// </summary> |
| | 47 | | /// <param name="archiveInfo">The file and/or directory info.</param> |
| | 48 | | /// <param name="lineAction">The line action.</param> |
| | 49 | | /// <param name="entriesProjector">The filter zip archive entries.</param> |
| | 50 | | /// <remarks> |
| | 51 | | /// This member is designed for compressed text documents that are too large to load into memory. |
| | 52 | | /// The <c>fileAction</c> includes the line number and the current line. |
| | 53 | | /// </remarks> |
| | 54 | | public static void ReadZipArchiveEntriesByLine(this FileInfo archiveInfo, Action<int, string> lineAction, |
| | 55 | | Func<ReadOnlyCollection<ZipArchiveEntry>, IEnumerable<ZipArchiveEntry>> entriesProjector) => |
| 1 | 56 | | ProgramFileUtility.ReadZipArchiveEntriesByLine(archiveInfo, lineAction, entriesProjector); |
| | 57 | |
|
| | 58 | | /// <summary> |
| | 59 | | /// Centralizes the use of <see cref="ZipArchive"/> |
| | 60 | | /// </summary> |
| | 61 | | /// <param name="archiveInfo"></param> |
| | 62 | | /// <param name="archiveAction"></param> |
| | 63 | | public static void UseZipArchive(this FileInfo archiveInfo, Action<ZipArchive?> archiveAction) => |
| 1 | 64 | | ProgramFileUtility.UseZipArchive(archiveInfo, archiveAction); |
| | 65 | |
|
| | 66 | | /// <summary> |
| | 67 | | /// Centralizes the use of <see cref="ReadOnlyCollection{ZipArchiveEntry}"/>. |
| | 68 | | /// </summary> |
| | 69 | | /// <param name="archiveInfo"></param> |
| | 70 | | /// <param name="entriesAction"></param> |
| | 71 | | public static void UseZipArchiveEntries(this FileInfo archiveInfo, |
| | 72 | | Action<ReadOnlyCollection<ZipArchiveEntry>> entriesAction) => |
| 0 | 73 | | ProgramFileUtility.UseZipArchiveEntries(archiveInfo, entriesAction); |
| | 74 | |
|
| | 75 | | /// <summary> |
| | 76 | | /// Centralizes the use of <see cref="ReadOnlyCollection{ZipArchiveEntry}"/>. |
| | 77 | | /// </summary> |
| | 78 | | /// <param name="archiveInfo"></param> |
| | 79 | | /// <param name="entriesAction"></param> |
| | 80 | | /// <param name="entriesProjector"></param> |
| | 81 | | public static void UseZipArchiveEntries(this FileInfo archiveInfo, |
| | 82 | | Action<ReadOnlyCollection<ZipArchiveEntry>> entriesAction, |
| | 83 | | Func<ReadOnlyCollection<ZipArchiveEntry>, ReadOnlyCollection<ZipArchiveEntry>> entriesProjector) => |
| 0 | 84 | | ProgramFileUtility.UseZipArchiveEntries(archiveInfo, entriesAction, entriesProjector); |
| | 85 | |
|
| | 86 | | /// <summary> |
| | 87 | | /// Write zip archive entry with <see cref="CompressionLevel.Optimal"/>. |
| | 88 | | /// </summary> |
| | 89 | | /// <param name="archiveInfo">The file and/or directory info.</param> |
| | 90 | | /// <param name="fileInfo">The file information.</param> |
| | 91 | | public static void WriteZipArchiveEntry(this FileInfo archiveInfo, FileInfo fileInfo) => |
| 0 | 92 | | ProgramFileUtility.WriteZipArchiveEntry(archiveInfo, fileInfo); |
| | 93 | |
|
| | 94 | | /// <summary> |
| | 95 | | /// Write zip archive entry. |
| | 96 | | /// </summary> |
| | 97 | | /// <param name="archiveInfo">The file and/or directory info.</param> |
| | 98 | | /// <param name="fileInfo">The file information.</param> |
| | 99 | | /// <param name="compressionLevel">The <see cref="CompressionLevel"/></param> |
| | 100 | | public static void WriteZipArchiveEntry(this FileInfo archiveInfo, FileInfo fileInfo, |
| | 101 | | CompressionLevel compressionLevel) => |
| 0 | 102 | | ProgramFileUtility.WriteZipArchiveEntry(archiveInfo, fileInfo, compressionLevel); |
| | 103 | | } |