Tar
๐ค AI-Generated Content
This documentation was generated with AI assistance and is still being audited. Some, or potentially a lot, of this information may be inaccurate. Learn more.
provide.foundation.archive.tar
¶
Classes¶
TarArchive
¶
Bases: BaseArchive
TAR archive implementation.
Creates and extracts TAR archives with optional metadata preservation and deterministic output for reproducible builds.
Functions¶
create
¶
Create TAR archive from source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Path
|
Source file or directory to archive |
required |
output
|
Path
|
Output TAR file path |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to created archive |
Raises:
| Type | Description |
|---|---|
ArchiveError
|
If archive creation fails |
Source code in provide/foundation/archive/tar.py
extract
¶
Extract TAR archive to output directory with decompression bomb protection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
archive
|
Path
|
TAR archive file path |
required |
output
|
Path
|
Output directory path |
required |
limits
|
ArchiveLimits | None
|
Optional extraction limits (uses DEFAULT_LIMITS if None) |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to extraction directory |
Raises:
| Type | Description |
|---|---|
ArchiveError
|
If extraction fails, archive contains unsafe paths, or exceeds limits |
Source code in provide/foundation/archive/tar.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
list_contents
¶
List contents of TAR archive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
archive
|
Path
|
TAR archive file path |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of file paths in archive |
Raises:
| Type | Description |
|---|---|
ArchiveError
|
If listing fails |
Source code in provide/foundation/archive/tar.py
validate
¶
Validate TAR archive integrity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
archive
|
Path
|
TAR archive file path |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if archive is valid, False otherwise |
Note: This method intentionally catches all exceptions and returns False. This is NOT an error suppression case - returning False on any exception is the expected validation behavior. Do NOT replace this with @resilient decorator.
Source code in provide/foundation/archive/tar.py
Functions¶
deterministic_filter
¶
Tarfile filter for deterministic/reproducible archives.
Resets user/group info and modification time to ensure consistent output for reproducible builds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tarinfo
|
TarInfo
|
TarInfo object to modify |
required |
Returns:
| Type | Description |
|---|---|
TarInfo
|
Modified TarInfo object with deterministic metadata |
Examples:
>>> import tarfile
>>> with tarfile.open("archive.tar", "w") as tar:
... tar.add("myfile.txt", filter=deterministic_filter)
Notes
This filter sets: - uid/gid to 0 (root) - uname/gname to empty strings - mtime to 0 (1970-01-01)
This ensures archives are byte-for-byte identical when created from the same source, regardless of filesystem timestamps or ownership.