1using System.IO.Compression;
7[BadInteropApi(
"Zip",
true)]
30 [BadMethod(
"ToDirectory",
"Extracts a Zip Archive to the given directory")]
31 private void ToDirectoryApi([BadParameter(description:
"Output Directory")] string outputDir,
32 [BadParameter(description:
"Input File")] string inputFile)
43 [BadMethod(
"FromDirectory",
"Creates a new Zip Archive from the given directory")]
44 private void FromDirectoryApi([BadParameter(description:
"Input Directory")] string inputDir,
45 [BadParameter(description:
"Output File")] string outputFile)
58 using ZipArchive archive =
new ZipArchive(input, ZipArchiveMode.Read);
60 foreach (ZipArchiveEntry entry
in archive.Entries)
62 string outputFile = Path.Combine(outputDir, entry.FullName);
63 string outputParent = Path.GetDirectoryName(outputFile)!;
66 using Stream e = entry.Open();
78 using ZipArchive archive =
new ZipArchive(output, ZipArchiveMode.Create);
83 foreach (
string file
in files)
85 string zipPath = file.Remove(0, inputDir.Length + 1)
87 ZipArchiveEntry entry = archive.CreateEntry(zipPath);
88 using Stream es = entry.Open();
Public interface for the filesystem abstraction of the BadScript Engine.
static IFileSystem Instance
File System implementation.
void ToDirectory(string outputDir, Stream input)
Decompresses the given stream to the given output directory.
void FromDirectoryApi([BadParameter(description:"Input Directory")] string inputDir, [BadParameter(description:"Output File")] string outputFile)
Compreses the given directory to the given output file.
readonly IFileSystem m_FileSystem
The FileSystem Instance.
BadZipApi(IFileSystem fileSystem)
Creates a new API Instance.
void ToDirectoryApi([BadParameter(description:"Output Directory")] string outputDir, [BadParameter(description:"Input File")] string inputFile)
Decompresses the given file to the given output directory.
void FromDirectory(string inputDir, Stream output)
Compreses the given directory to the given output stream.
Defines the interface for a file system.
void CreateDirectory(string path, bool recursive=false)
Creates a new directory.
Stream OpenWrite(string path, BadWriteMode mode)
Opens a file for writing.
IEnumerable< string > GetFiles(string path, string extension, bool recursive)
Returns all files in the given directory that match the specified extension.
Stream OpenRead(string path)
Opens a file for reading.
Contains IO Implementation for the BadScript2 Runtime.
BadWriteMode
The Write Modes of the File System Abstraction.
Contains Compression Extensions and APIs for the BadScript2 Runtime.