compress static method
Compresses files from the source directory into a ZIP archive.
source- Source directory path containing files to compressdestination- Destination path for the compressed archive
Returns the process exit code (0 indicates success).
The compression includes all files in the source directory and creates a file named "debug_symbols.zip" in the source directory. The method uses platform-specific compression tools:
- Windows: PowerShell's
Compress-Archivecmdlet - macOS/Linux:
zipcommand with recursive option
Throws UnsupportedError for unsupported platforms.
Example usage:
final exitCode = await CompressFiles.compress(
'/path/to/source/directory',
'/path/to/output.zip',
);
if (exitCode == 0) {
print('Compression successful');
} else {
print('Compression failed with exit code: $exitCode');
}
Implementation
static Future<int> compress(String source, String destination) {
if (Platform.isWindows) {
// Use PowerShell Compress-Archive to create ZIP file
return Process.run(
"powershell",
[
"Compress-Archive",
"-Path",
"*", // Compress all files in the working directory
"-DestinationPath",
"debug_symbols.zip",
],
runInShell: true,
workingDirectory: source, // Set working directory to source path
).then((value) => value.exitCode);
} else if (Platform.isMacOS || Platform.isLinux) {
// Use zip command with recursive option
return Process.run(
"zip",
[
"-r",
"debug_symbols.zip",
".",
],
workingDirectory: source) // Set working directory to source path
.then((value) => value.exitCode);
} else {
throw UnsupportedError("Unsupported platform for compression");
}
}