473,395 Members | 1,412 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

using tarfile with an open file object

I've been using tarfile like this

import tarfile
tar = tarfile.open('path_to_tar_archive', 'r:gz')
But I need to use it like this:

archive = open('path_to_tar_archive', 'r')
tar = tarfile.open(archive.readlines())

or something similar. In essence I need to use tarfile to manipulate an
already open file object. I searched in the docs but didn't find
anything. Maybe I just over looked the obvious.

Does any one know how to do this?

Thanks
-matthew
Jul 19 '05 #1
1 2974
Matthew Thorley wrote:
I've been using tarfile like this

import tarfile
tar = tarfile.open('path_to_tar_archive', 'r:gz')
But I need to use it like this:

archive = open('path_to_tar_archive', 'r')
tar = tarfile.open(archive.readlines())

or something similar. In essence I need to use tarfile to manipulate an
already open file object. I searched in the docs but didn't find
anything. Maybe I just over looked the obvious.

Does any one know how to do this?


I don't know if this is in the docs (please check and submit a bug
report if it's not), but the source shows that you should be able to do
this:

tar = tarfile.open(fileobj=archive)

and carry on as you wish.

-Peter
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Josh Smith | last post by:
In Python 2.3 there is a new library for handling tarfiles. However, there doesn't seem to be any documentation on handling end-of-tape conditions. I've googled for it and checked the docs, I've...
5
by: Hans-Joachim Widmaier | last post by:
Although I've done a bit of ranting before on this, noone seems to have noticed. I'll try again, hopefully more to the point. One of the additions in the standard library I liked most is the...
8
by: Jay Donnell | last post by:
Is there a way to use the tarfile module to recursively compress the contents of a directory and maintain the directory structure in the tar archive? Simply doing os.system('tar -czvf ' +...
4
by: Claudio Grondi | last post by:
I need to unpack on a Windows 2000 machine some Wikipedia media .tar archives which are compressed with TAR 1.14 (support for long file names and maybe some other features) . It seems, that...
3
by: justin.vanwinkle | last post by:
Hello everyone, I need some tar functionality for my program. Currently the following code properly displays tar archives, and tar.gz archives. However, it chokes on tar.bz2 archives with the...
3
by: John Salerno | last post by:
Here's the name of a file I have: wxPython-newdocs-2.6.3.3.tar.bz2 Now, I tried this: import tarfile tar = tarfile.open('wxPython-newdocs-2.6.3.3.tar.bz2', 'r:bz2') but got this: ...
7
by: aurora00 | last post by:
I have a program that generates a number of files that will be packaged into a tarball. Can I stream the content into TarFile without first writing them out to the file system? All add(), addfile()...
6
by: sebastian.noack | last post by:
Hi, is there a way to or at least a reason why I can not use tarfile to create a gzip or bunzip2 compressed archive in the memory? You might might wanna answer "use StringIO" but this isn't...
1
by: boblatest | last post by:
Hello, I'm trying to catch an "EOFError" exception that occurs when reading truncated tarfile. Here's my routine, and below that the callback trace. Note that although I'm trying to catch all...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.