FileSystemZipExtensions
Extension methods for IFileSystem to work with ZIP archives.
Methoden
public static IEnumerable<ValueTuple<string, Stream>> ReadEntries(IFileSystem fs, string directoryPath, string searchPattern, SearchOption searchOption)
result = FileSystemZipExtensions.ReadEntries(fs, directoryPath, searchPattern, searchOption)
Reads all files from a directory and returns them as a collection of entries.
- fs
- The file system to use.
- directoryPath
- Directory path to read files from.
- searchPattern
- Search pattern for files.
- searchOption
- Whether to search subdirectories.
Rückgabe: A collection of file entries with relative paths and streams.
public static IEnumerable<ValueTuple<string, Stream>> Unzip(IFileSystem fs, string zipPath, Func<string, bool> filter)
result = FileSystemZipExtensions.Unzip(fs, zipPath, filter)
Opens a ZIP archive file and returns its entries as streams.
- fs
- The file system to use.
- zipPath
- Path to the ZIP archive file.
- filter
- Optional filter function for entry names.
Rückgabe: An enumerable of entries. The enumerator must be disposed after use (foreach does this automatically).
public static void UnzipTo(IFileSystem fs, string zipPath, string destPath, bool overwrite)
FileSystemZipExtensions.UnzipTo(fs, zipPath, destPath, overwrite)
Extracts a ZIP archive to the specified directory.
- fs
- The file system to use.
- zipPath
- Path to the ZIP archive file.
- destPath
- Destination directory path.
- overwrite
- Whether to overwrite existing files.
public static void UnzipTo(IFileSystem fs, Stream zipStream, string destPath, bool overwrite)
FileSystemZipExtensions.UnzipTo(fs, zipStream, destPath, overwrite)
Extracts a ZIP archive stream to the specified directory.
- fs
- The file system to use.
- zipStream
- Stream containing the ZIP archive.
- destPath
- Destination directory path.
- overwrite
- Whether to overwrite existing files.
public static Task UnzipToAsync(IFileSystem fs, string zipPath, string destPath, bool overwrite, CancellationToken cancellationToken)
result = FileSystemZipExtensions.UnzipToAsync(fs, zipPath, destPath, overwrite, cancellationToken)
Extracts a ZIP archive to the specified directory asynchronously.
- fs
- The file system to use.
- zipPath
- Path to the ZIP archive file.
- destPath
- Destination directory path.
- overwrite
- Whether to overwrite existing files.
- cancellationToken
- A cancellation token.
public static Task UnzipToAsync(IFileSystem fs, Stream zipStream, string destPath, bool overwrite, CancellationToken cancellationToken)
result = FileSystemZipExtensions.UnzipToAsync(fs, zipStream, destPath, overwrite, cancellationToken)
Extracts a ZIP archive stream to the specified directory asynchronously.
- fs
- The file system to use.
- zipStream
- Stream containing the ZIP archive.
- destPath
- Destination directory path.
- overwrite
- Whether to overwrite existing files.
- cancellationToken
- A cancellation token.
public static void WriteEntries(IFileSystem fs, string directoryPath, IEnumerable<ValueTuple<string, Stream>> entries, bool overwrite)
FileSystemZipExtensions.WriteEntries(fs, directoryPath, entries, overwrite)
Writes a collection of entries to a directory.
- fs
- The file system to use.
- directoryPath
- Destination directory path.
- entries
- The entries to write.
- overwrite
- Whether to overwrite existing files.
public static Task WriteEntriesAsync(IFileSystem fs, string directoryPath, IEnumerable<ValueTuple<string, Stream>> entries, bool overwrite, CancellationToken cancellationToken)
result = FileSystemZipExtensions.WriteEntriesAsync(fs, directoryPath, entries, overwrite, cancellationToken)
Writes a collection of entries to a directory asynchronously.
- fs
- The file system to use.
- directoryPath
- Destination directory path.
- entries
- The entries to write.
- overwrite
- Whether to overwrite existing files.
- cancellationToken
- A cancellation token.
public static void Zip(IFileSystem fs, string zipPath, IEnumerable<ValueTuple<string, Stream>> entries, CompressionLevel level)
FileSystemZipExtensions.Zip(fs, zipPath, entries, level)
Creates a ZIP archive from a collection of entries and writes to a file.
- fs
- The file system to use.
- zipPath
- Path for the output ZIP file.
- entries
- The entries to include in the archive.
- level
- Compression level.
public static void Zip(IFileSystem fs, Stream zipStream, IEnumerable<ValueTuple<string, Stream>> entries, CompressionLevel level, bool leaveOpen)
FileSystemZipExtensions.Zip(fs, zipStream, entries, level, leaveOpen)
Creates a ZIP archive from a collection of entries and writes to a stream.
- fs
- The file system to use.
- zipStream
- Output stream for the ZIP archive.
- entries
- The entries to include in the archive.
- level
- Compression level.
- leaveOpen
- Whether to leave the stream open after creating the archive.
public static Task ZipAsync(IFileSystem fs, string zipPath, IEnumerable<ValueTuple<string, Stream>> entries, CompressionLevel level, CancellationToken cancellationToken)
result = FileSystemZipExtensions.ZipAsync(fs, zipPath, entries, level, cancellationToken)
Creates a ZIP archive from a collection of entries and writes to a file asynchronously.
- fs
- The file system to use.
- zipPath
- Path for the output ZIP file.
- entries
- The entries to include in the archive.
- level
- Compression level.
- cancellationToken
- A cancellation token.
public static Task ZipAsync(IFileSystem fs, Stream zipStream, IEnumerable<ValueTuple<string, Stream>> entries, CompressionLevel level, bool leaveOpen, CancellationToken cancellationToken)
result = FileSystemZipExtensions.ZipAsync(fs, zipStream, entries, level, leaveOpen, cancellationToken)
Creates a ZIP archive from a collection of entries and writes to a stream asynchronously.
- fs
- The file system to use.
- zipStream
- Output stream for the ZIP archive.
- entries
- The entries to include in the archive.
- level
- Compression level.
- leaveOpen
- Whether to leave the stream open after creating the archive.
- cancellationToken
- A cancellation token.
public static void ZipFrom(IFileSystem fs, string sourcePath, string zipPath, CompressionLevel level, bool includeBaseDirectory)
FileSystemZipExtensions.ZipFrom(fs, sourcePath, zipPath, level, includeBaseDirectory)
Creates a ZIP archive from a directory.
- fs
- The file system to use.
- sourcePath
- Source directory path to archive.
- zipPath
- Path for the output ZIP file.
- level
- Compression level.
- includeBaseDirectory
- Whether to include the base directory name in the archive.
public static void ZipFrom(IFileSystem fs, string sourcePath, Stream zipStream, CompressionLevel level, bool includeBaseDirectory)
FileSystemZipExtensions.ZipFrom(fs, sourcePath, zipStream, level, includeBaseDirectory)
Creates a ZIP archive from a directory and writes to a stream.
- fs
- The file system to use.
- sourcePath
- Source directory path to archive.
- zipStream
- Output stream for the ZIP archive.
- level
- Compression level.
- includeBaseDirectory
- Whether to include the base directory name in the archive.
public static Task ZipFromAsync(IFileSystem fs, string sourcePath, string zipPath, CompressionLevel level, bool includeBaseDirectory, CancellationToken cancellationToken)
result = FileSystemZipExtensions.ZipFromAsync(fs, sourcePath, zipPath, level, includeBaseDirectory, cancellationToken)
Creates a ZIP archive from a directory asynchronously.
- fs
- The file system to use.
- sourcePath
- Source directory path to archive.
- zipPath
- Path for the output ZIP file.
- level
- Compression level.
- includeBaseDirectory
- Whether to include the base directory name in the archive.
- cancellationToken
- A cancellation token.
public static Task ZipFromAsync(IFileSystem fs, string sourcePath, Stream zipStream, CompressionLevel level, bool includeBaseDirectory, CancellationToken cancellationToken)
result = FileSystemZipExtensions.ZipFromAsync(fs, sourcePath, zipStream, level, includeBaseDirectory, cancellationToken)
Creates a ZIP archive from a directory and writes to a stream asynchronously.
- fs
- The file system to use.
- sourcePath
- Source directory path to archive.
- zipStream
- Output stream for the ZIP archive.
- level
- Compression level.
- includeBaseDirectory
- Whether to include the base directory name in the archive.
- cancellationToken
- A cancellation token.