Archive File
An archive file is a file that is composed of one or more computer files along with metadata. Archive files are used to collect multiple data file together into a single file for easier portability and storage, or simply to compress files to use less storage space.
Different Types of Archive Formats:-
Examples:-
Creating a New Archive-
To create a new archive, open the Tarfile with a mode of 'w'
CODE:-
import tarfile
def hello(a):
print('creating archive')
with tarfile.open(a, mode='w') as out:
print('adding README.txt')
out.add('README.txt')
print()
print('Contents:')
with tarfile.open(a, mode='r') as t:
for member_info in t.getmembers():
print(member_info.name)
a = 'phayes-geoPHP-1.2-20-g6855624.tar.gz'
hello(a)
OUTPUT:-
let's run this code and see the output
Appending To Archives-
It is possible to append to an existing file by using mode 'a'.
CODE:-
import tarfile
def appending(a):
print('creating archive')
with tarfile.open(a, mode='w') as out:
out.add('README.txt')
print('contents:',)
with tarfile.open(a, mode='r') as t:
print([m.name for m in t.getmembers()])
print('adding index.rst')
with tarfile.open(a, mode='a') as out:
out.add('index.rst')
print('contents:',)
with tarfile.open(a, mode='r') as t:
print([m.name for m in t.getmembers()])
a='phayes-geoPHP-1.2-20-g6855624.tar.gz'
appending(a)
OUTPUT:-
let's run this code and we see that the resulting archive ends up with two members.
Name | Views | Likes |
---|---|---|
Python project_Speech to text | 478 | 3 |
Tarfile_Metadata | 378 | 6 |
Library_Tarfile | 631 | 5 |
python project_color detection | 538 | 3 |
Text to Speech using Python | 445 | 6 |
Tarfile_TarInfo Objects | 313 | 5 |
Tarfile_Extracting file from Archive | 264 | 3 |
Tarfile_generator function | 295 | 3 |
tarfile_targzstream | 259 | 7 |
Tarfile_Exception | 643 | 5 |
python Project_Detecting Fake news | 773 | 3 |
Tarfile_working with compressed archives | 328 | 5 |
Tarfile_Objects | 368 | 5 |
Project in python_color detection | 76 | 1 |
Tarfile_Archive Access | 343 | 5 |
Comments