Question

I apologize if the questions title is not clear.

I am creating a very large compressed TarFile using python.

I need to know if when using TarFile.Add() does that close and/or finalize the file added, or can the file still be modified?

For instance, if I were to create an empty text file and then add it to a TarFile, and then modify the text file, and then close the TarFile, would the changes made to the text file appear in the TarFile, or is the text file added as it was at the time of the TarFile.Add()?

Thank you.

Note: If it makes any sort of difference, the code is running on a Ubuntu machine, and the archive is also being created on the same machine.

Was it helpful?

Solution

The file contents won't get updated after you call add().

See the below code:

import tarfile

fp1 = open("hello.txt", "w")

tar = tarfile.open("myArchive.tar", "w")
tar.add("hello.txt")

fp1.write("Test String")
fp1.close()

tar.close()

After this is executed, 'hello.txt' will have "Test String", but the 'hello.txt' inside 'myArchive.tar' will be empty.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top