Archive
Creates an archive file (Zip, Tar, or TarGz) from one or more source files or directories.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.
Inputs
-
Source Path - Path(s) to the source file(s) or directory(ies) to archive. Can be:
- A single file path as a string (e.g.,
"/path/to/file.txt") - A single directory path as a string (e.g.,
"/path/to/folder") - An array of file and/or directory paths (e.g.,
["/path/to/file1.txt", "/path/to/folder", "/path/to/file2.pdf"])
- A single file path as a string (e.g.,
-
Target Path - Destination path for the archive file to be created. The file extension should match the archive type (e.g.,
"/path/to/archive.zip"for Zip type).
Options
Archive Type
- Type - The archive format to create. Available options:
- Zip - Universal archive format with good cross-platform compatibility
- Tar - Unix standard archive format without compression
- TarGz - Tar archive with Gzip compression
General Options
-
Make Directory All - Creates parent directories if they do not exist. Useful when the target path includes directories that haven't been created yet.
-
Continue On Error - If enabled, the archiving process will continue even if some files fail to be added. Failed files will be skipped instead of stopping the entire operation.
-
Overwrite Existing - Overwrites the target archive file if it already exists at the specified path.
-
Implicit Top Level Folder - Adds an implicit top-level folder to the archive. When extracting, all files will be placed inside this folder instead of directly in the extraction directory.
Zip-Specific Options
- Zip Compression Method - Compression method for Zip archives:
- Deflate (default) - Standard compression algorithm, provides good compression
- Store - No compression, files are stored as-is (faster but larger file size)
TarGz-Specific Options
-
Compression Level - Compression level for TarGz archives (1-9):
- Default - Uses the default compression level (usually 6)
- 1 - Fastest compression, larger file size
- 9 - Best compression, slower processing
- Levels 2-8 provide a balance between speed and compression ratio
-
Single Threaded - When enabled, uses single-threaded compression. By default, TarGz uses multi-threaded compression for better performance.
Examples
Example 1: Archive a Single File
Archive a single document file into a Zip archive:
// Set the source file path
msg.sourceFile = "/home/user/documents/report.pdf";
msg.archivePath = "/home/user/archives/report.zip";
Configure the Archive node:
- Source Path:
{{msg.sourceFile}} - Target Path:
{{msg.archivePath}} - Type: Zip
Example 2: Archive Multiple Files
Archive multiple files from different locations:
// Create an array of file paths to archive
msg.filesToArchive = [
"/home/user/documents/report.pdf",
"/home/user/data/sales.xlsx",
"/home/user/images/chart.png"
];
msg.archivePath = "/home/user/backup/monthly-report.zip";
Configure the Archive node:
- Source Path:
{{msg.filesToArchive}} - Target Path:
{{msg.archivePath}} - Type: Zip
Example 3: Archive a Directory with High Compression
Archive an entire directory with maximum compression:
// Set the directory to archive
msg.sourceDir = "/home/user/project";
msg.archivePath = "/home/user/backups/project-backup.tar.gz";
Configure the Archive node:
- Source Path:
{{msg.sourceDir}} - Target Path:
{{msg.archivePath}} - Type: TarGz
- Compression Level: 9
- Implicit Top Level Folder: Enabled
Example 4: Archive with Error Handling
Archive a directory tree, continuing even if some files are inaccessible:
// Archive a large directory tree
msg.sourceDir = "/home/user/documents";
msg.archivePath = "/home/user/backups/docs-backup.zip";
Configure the Archive node:
- Source Path:
{{msg.sourceDir}} - Target Path:
{{msg.archivePath}} - Type: Zip
- Continue On Error: Enabled
- Make Directory All: Enabled
- Overwrite Existing: Enabled
Example 5: Create Uncompressed TAR Archive
Create a TAR archive without compression (useful for subsequent processing):
// Create uncompressed tar for fast archiving
msg.sourcePaths = [
"/home/user/logs/app.log",
"/home/user/logs/error.log",
"/home/user/logs/access.log"
];
msg.archivePath = "/home/user/archives/logs.tar";
Configure the Archive node:
- Source Path:
{{msg.sourcePaths}} - Target Path:
{{msg.archivePath}} - Type: Tar
Usage Tips
-
Array vs Single Path: When archiving multiple files, pass an array of paths. For a single file or directory, you can use a string or a single-element array.
-
Archive Format Selection:
- Use Zip for maximum compatibility with Windows and other platforms
- Use Tar for Unix/Linux environments when compression is not needed
- Use TarGz when you need both archiving and compression
-
Compression Level: Higher compression levels (7-9) significantly reduce file size but take longer to process. Use level 1-3 for faster archiving when file size is less critical.
-
Top Level Folder: Enable "Implicit Top Level Folder" to avoid cluttering the extraction directory. This creates a single root folder containing all archived content.
-
Directory Creation: Enable "Make Directory All" when the target path includes directories that may not exist yet.
-
Performance Optimization:
- For large archives, consider using multi-threaded compression (disable Single Threaded option)
- Use Store method for Zip if files are already compressed (images, videos)
Common Errors and Solutions
Error: "Source Path cannot be empty"
Cause: The Source Path input is not provided or is empty.
Solution: Ensure you provide a valid file or directory path, or an array of paths.
Error: "Target Path cannot be empty"
Cause: The Target Path input is not provided or is empty.
Solution: Provide a valid destination path for the archive file.
Error: "Archive Type should be selected"
Cause: An invalid archive type was specified.
Solution: Ensure the Type option is set to one of: Zip, Tar, or TarGz.
Error: File or directory not found
Cause: One or more source paths do not exist on the file system.
Solution:
- Verify all source paths are correct and exist
- Enable "Continue On Error" if some files might not exist and you want to archive the rest
Error: Permission denied
Cause: Insufficient permissions to read source files or write to the target location.
Solution:
- Ensure the automation has read permissions for all source files
- Verify write permissions for the target directory
- On Unix/Linux, check file ownership and permissions
Related Nodes
- Unarchive - Extract all files from an archive
- Extract File - Extract a specific file from an archive
- Inspect Archive File - List files in an archive without extracting
-
- Compress a single file using various compression formats